I have some long processing and want to update the user on what is happening.
So I have created a Scrolling TextView in Interface Builder (in fact it is a NSScroll view) and I’m writing to it to inform of the progress.
so in my script I have a property that is linked to the NSScrollview in IB
property myScrollView : missing value
And while doing my processing I send sting to my textView using the handler below that is called from my processing routines.
on logToMyScrollView(aMessage)
myScrollView's documentView()'s textStorage()'s mutableString()'s appendString_(aMessage & return)
set newTextLength to myScrollView's documentView()'s textStorage()'s mutableString()'s |length|() as integer
myScrollView's documentView()'s scrollRangeToVisible_({|location|:newTextLength, |length|:0})
end logToMyScrollView
The code works fine and it scroll to the end as I wish, except of course that the update on the textView happens once the processing is done, which deserves my goal.
The issue I have is that when I thread my processing handler to let the UI updates to happen I have freeze of the application at various time, sometime even right when I press my “go” button, sometimes when the processing it’s almost done, however I never get the all things to be done except when I don’t thread bench().
Here is how I threaded my application
on runTest_(sender)
performSelectorInBackground_withObject_("bench", MyAppDelegate)
end runTest_
And my bench() handler is doing the job and calling logToMyScrollView() handler.
on bench()
logToMyScrollView("doing this")
--doing some work
logToMyScrollView("I done with this")
logToMyScrollView("doing that")
--doing some work
logToMyScrollView("I done with that")
-- and so on
end bench
If I sample the application with activity monitor while it is frozen, the main thread looks to be locked on __semwait_signal (see below)
This is also the symbol display on debugger when I force quit the application.
So I’m wondering if I’m not missing some handlers that are called by the NSScrollView that I’m not serving hence the freeze.
Anybody can help ?
Call graph:
2719 Thread_76975 DispatchQueue_1: com.apple.main-thread (serial)
2719 start
2719 main
2719 NSApplicationMain
2719 -[NSApplication run]
2719 -[NSApplication sendEvent:]
2719 -[NSWindow sendEvent:]
2719 -[NSControl mouseDown:]
2719 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
2719 -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
2719 -[NSControl sendAction:to:]
2719 -[NSApplication sendAction:to:from:]
2719 _CF_forwarding_prep_0
2719 forwarding
2719 -[BAObjectProto forwardInvocation:]
2719 -[BAObjectProto invokeScriptHandler:args:error:]
2719 +[BAObjectProto invokeScriptHandler:forObject:args:error:]
2719 OSAExecuteEvent
2719 AppleScriptComponent
2719 CallComponentFunction
2719 ASExecuteEvent(AEDesc const*, unsigned int, int, unsigned int*)
2719 UASExecute1()
2719 UASRemoteSend(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char*)
2719 TUASApplication::Send(TStackFrame_UASRemoteSend*, AEDesc*, AEDesc*, unsigned char, unsigned char, unsigned char)
2719 ComponentSend(AEDesc const*, AEDesc*, int, int)
2719 AppleScriptUnlocker::~AppleScriptUnlocker()
2719 _pthread_cond_wait
2719 __semwait_signal