<bh************@gmail.comwrote:
I m kind of new to multithreading programming and try to implement one
solution. The problem I have is, I have one background thread which
does time consuming processing. The parent(calling) thread can be
windows application or console application or simple object. How can I
pass message from Background thread to parent thread. The message is
of type custom object so that I cant use BackgroundWorker class's
progress report method. I tried delegates but to update windows
control I have to use Invoke method. But I want the solution so
generic that when it come to parent they can directly update control
without considering threading in mind.
Any help is highly appreciated...thanks in advance..!!!
You'll need Control.Invoke/BeginInvoke *somewhere* in order to marshal
the call back to the UI thread. However, you can provide helper methods
or properties to do that, so that clients don't have to worry about the
delegates themselves.
Console applications are different beasts - in that case although there
may be a separate thread which created the worker thread, there's no
default way provided to make a call within that thread - it's only the
fact that WinForms runs a message pump which makes it possible for GUI
apps. You can't just interrupt an arbitrary thread and tell it to
execute a different bit of code suddenly - it has to co-operatively be
waiting for delegates to run, effectively. All this can be done in a
console app, of course, but it's more work than in a WinForms app.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too