Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to syncronize a process to a event that occurs after some GUI-updates (method doSomeGUIUpdates) by the application. im doing latter by invoking the method via Application.Current.Dispatcher.Invoke. in this case, this blocks my application. without this line, the EventWaitHandle works as it should.

how can i manage those GUI-updates that the EventWaitHandle works?


VB
dim eventhandle as New EventWaitHandle(False, EventResetMode.ManualReset)

sub main
	doSomeAsync

	eventhandle.WaitOne()
	
end sub


sub wait handles class2.myEvent
	eventhandle.Set()
end sub


'------
class2
	sub doSomeAsync
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, doSomeGUIUpdates) '< -- this line blocks the execution
		
		raise myEvent
	end sub
end class2
Posted

1 solution

This is a totally wrong idea. WaitOne is a blocking call, it actually puts the calling thread into a wait state. The calling thread is switched off an is not scheduled back to execution, thus wasting no CPU time. It sleeps until it is "waken up". One of the events waking up this thread is the signalling the event wait handle object from another thread, others include timeout, thread abort, etc. This is very useful and important feature, to put a thread to sleep, it is used for thread synchronization, throttling some activities by another thread. That said, the purpose is something opposite to "doing GUI updates". You have to do UI updates in some other thread.

So, I explained the wrong idea, so what would be the right one? It's possible that you can get further advice if you explain what do you want to achieve. This is not what your post does. You don't explain your real ultimate goal, but present a fictional goal, which mix up what you want to achieve with your wrong idea on "how".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900