471,354 Members | 1,199 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Notification from worker thread to Main thread

Tim
The are 2 threads - main thread and worker thread. The main thread
creates the worker thread and then the worker thread runs in an infinite
while loop till it is asked to exit by setting an event. The worker thread
instantiates an object and calls methods of that object. If some method call
fails, the main thread needs to be notified about the failure. What
mechanisms exist for notifying the main thread about the worker thread's
status - for example - 'a method call failed'?
Jan 2 '06 #1
2 3974
Tim,

The only way to do things like this is to have the thread running in a
loop of some sort, and then set the state that is checked in each iteration
of the loop to see if something happened. This is what is acheived in
Windows Forms, when a call has to be made to the UI thread (through windows
messages).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
The are 2 threads - main thread and worker thread. The main thread
creates the worker thread and then the worker thread runs in an infinite
while loop till it is asked to exit by setting an event. The worker thread
instantiates an object and calls methods of that object. If some method
call
fails, the main thread needs to be notified about the failure. What
mechanisms exist for notifying the main thread about the worker thread's
status - for example - 'a method call failed'?

Jan 2 '06 #2
Tim
Hi Nicholas,

Is there some mechanism like callback that can be implemented, so that
when the secondary thread detects some kind of failure (when it makes its
method calls), it calls back a method running on the primary thread. That
callback method could set an event (Synchronization object) asking the
secondary thread to exit or perform other actions.

Can events and Delegates be used for the same? I am not sure if they can be
used in this scenario.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

The only way to do things like this is to have the thread running in a
loop of some sort, and then set the state that is checked in each iteration
of the loop to see if something happened. This is what is acheived in
Windows Forms, when a call has to be made to the UI thread (through windows
messages).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
The are 2 threads - main thread and worker thread. The main thread
creates the worker thread and then the worker thread runs in an infinite
while loop till it is asked to exit by setting an event. The worker thread
instantiates an object and calls methods of that object. If some method
call
fails, the main thread needs to be notified about the failure. What
mechanisms exist for notifying the main thread about the worker thread's
status - for example - 'a method call failed'?


Jan 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Will | last post: by
3 posts views Thread by Jacob | last post: by
5 posts views Thread by Stephen Lamb | last post: by
7 posts views Thread by Jeff Stewart | last post: by
7 posts views Thread by Charles Law | last post: by
5 posts views Thread by Soren S. Jorgensen | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.