Notify from worker thread

T

Tomaz Koritnik

Hi

I still have problem with this. I wan't to execute a method in main thread
after worker thread completes some work. In GUI application I'd use
Control.Invoke (control would be the main form), but the same thread could
be run from console app or WebService app. What would be the mechanism of
executing method in main thread with these two apps? If the same, I'd have
to create some kind of windowed control. It's probably legal to do this in
WebService right :)?

regards
Tomaz
 
A

AlexS

Tomasz,

probably easiest way is to define event in the thread and assign event
handler to it in your main thread when starting. Or to pass delegate like
callback.

HTH
Alex
 
R

Richard Blewett [DevelopMentor]

In this situation its useful to realise that, Control.Invoke or BeginInvoke are simply the Control's implementation of ISynchronizeInvoke.Invoke and BeginInvoke. So for console and web apps, simply create an implementation of ISynchronizeInvoke that updates the necessary data (using locking where necessary) and pass that to the component.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi

I still have problem with this. I wan't to execute a method in main thread
after worker thread completes some work. In GUI application I'd use
Control.Invoke (control would be the main form), but the same thread could
be run from console app or WebService app. What would be the mechanism of
executing method in main thread with these two apps? If the same, I'd have
to create some kind of windowed control. It's probably legal to do this in
WebService right :)?

regards
Tomaz
 
J

Jon Skeet [C# MVP]

Tomaz Koritnik said:
I still have problem with this. I wan't to execute a method in main thread
after worker thread completes some work. In GUI application I'd use
Control.Invoke (control would be the main form), but the same thread could
be run from console app or WebService app. What would be the mechanism of
executing method in main thread with these two apps? If the same, I'd have
to create some kind of windowed control. It's probably legal to do this in
WebService right :)?

Well, what is the main thread doing while all this is happening? You
basically need it to be waiting for an event of some description.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top