Tom,
Yes, the callback occurs on thread B.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Tom,
If I understand you correctly, notificationCallback is the method that
is being called back when the work is complete. If this is the case, then
the method will be called on the thread that was doing the work, not on the
thread that the thread was started from.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
I think you do. I'll describe it in short.
Thread A is the thread that starts the worker thread (B). Thread A
passes
the AsyncCallback delegate-object to thread B on startup. The idea is that
when thread B has done working and is about to stop, it calls the delegate
to notify (1) completion and (2) results (if any) to thread A.
So thread B, at the end of the operation, calls:
notificationCallback( asyncResults );
My question, in concreto, is whether the actual call to the underlying
method in the delegate is called on Thread A or on Thread B. If I understand
you correctly, you say that the actual method is executed on thread B.
Correct?
To clarify. In my current setting, the workerthread is modeled as a
workerthread class. Any specific worker thread derives from the base
thread-class (to avoid having to rewrite plumbing code for each specific
worker thread). The worker thread class takes an AsyncCallback object on
construction. This is used to signal completion. Some pseudo-code:
class ExampleWorkerThreadBase
{
ExampleWorkerThreadBase(AsyncCallback notificationCallback);
private void ThreadFn() { // actual thread function
// ...
DoWork();
notificationCallback( asyncResults );
}
protected abstract void DoWork();
// ...
}
Now the reason why I asked the question, is that the
notificationCallback
could be to a UI thread which uses the results to update the UI. Now of
course, the worker thread cannot touch the UI directly (at least, in MFC
this was true). So the noficationCallback shouldn't either.
Currently, in the UI thread I am passing a delegate to a function that
calls Invoke, to ensure that the UI update is done in the UI thread.