473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 4118
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric Marvets | last post by:
I want to make the main thread in my app sleep while I have a worker do some arbitrary task. The problem is waking the main thread back up. Can anyone make this code sample work? private void...
3
by: Will | last post by:
I have a Manager thread that launches a variable number of Worker threads. When each Worker thread finishes, I want it to notify the Manager thread that it's done so that the Manager thread can...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
5
by: Hao L | last post by:
For example, void WorkerMethod() { ... UnregisterAllHotkeys();} void UnregisterAllHotKeys { for(...) {UnregisterHotKey(...);}} UnregisterHotKey is an API function that must be on the thread...
7
by: Jeff Stewart | last post by:
I need a thread to run a subroutine which updates my main form's progress bar. I've properly marshaled all UI updates to the main UI thread, and after the main thread starts the worker thread, it...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
5
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.