Update a window from inside a loop

I want to read a text file to produce a breakdown of certain categories by year for the last 5 years but the file is large and takes time to display the complete window. The program loops through all the data accumulating totals (file is in year sequence) so is it possible to update the window showing each year as it completes from within the loop. Hope this makes sense, my expertise in ApplescriptObjC is limited, I’ve only ever written projects where you hit a push button to display a window. Have tried displayIfNeeded() but no solution. Any guidance would be gratefully received!

You need to force the run loop to run each time. Try calling this handler when you want the screen to update:

on doEventFetch()
	repeat
		set theEvent to current application's NSApp's nextEventMatchingMask:((current application's NSLeftMouseDownMask) + (get current application's NSKeyDownMask)) untilDate:(missing value) inMode:(current application's NSEventTrackingRunLoopMode) dequeue:true
		if theEvent is missing value then
			exit repeat
		else
			current application's NSApp's sendEvent:theEvent
		end if
	end repeat
end doEventFetch

Hi Shane
Many thanks for reply, however, I have no idea what the handler does!!
Do I have to replace missing value with a value, if so, what?
Sorry to be dense but this is way outside my comfort zone, perhaps I should add a push button to display each year rather than wait untill all years have been accumulated.

You use the handler as-is — just call it every time you want the display to update.

Many thanks, works exactly as required, all I have to do now is understand how it does it!!!