472,974 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,974 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 4075
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.