[RESOLVED] [2008] Calling a function from another thread
Hello,
I have a function which is a callback. Code sippet below.
However, as the OnIncomingCall() will be on a different thread, I don't think it can call the IncomingCallAlert(). With controls you can use a delegate and invoke the control.
Which is the best way to do the same with a function?
Many thanks for any advice,
Steve
Code:
private sub OnIncomingCall()
.
.
IncomingCallAlert()
.
Sub End
private sub IncomingCallAlert()
'Play sound
Sub End
Re: [2008] Calling a function from another thread
You don't invoke a control. You use a control to invoke a delegate and you use the delegate to marshal a method call to the UI thread. The reason you need to do that is that you cannot access the handle of a control on a thread that doesn't own it. That's the only reason you need to do it. If you're not accessing controls then there's no need for you to do that. You can call any method you like on any thread you like. All members are available to all threads at all times. That's exactly why you need to synchronise multiple threads: because they can all access the same data.
In short, just call the method without regard for the thread it's executing on.