I've got a basic question about threading which I'm hoping someone here will
be able to answer:
Let's say my calling CallingClass has instantiated and started a worker
thread. When my worker thread has completed, it fires an event which
CallingClass has an event handler listening for.
My question is this: in which thread is that event handler operating? The
worker's or CallingClass's? The issue I'm running into is that if I include
a Worker.Join() call within the event handler on CallingClass, it just sits
there forever waiting for the worker thread to stop.
Is this even the proper to signal the end of a thread? I have some
processing that is waiting for the thread is completely finish and shutdown,
and I need a way to find that out. Any help someone can provide would be
greatly appreciated.
Cheers, Jon 3 1964
The event handler is ruiing on the worker's thread, you can see this by
placing a breakpoint in the event handlers and then looking at the
Threads window to see the thread that is active. Or you can use the
ThreadID's to check which thread is active, just dump the ThreadID's to
the console.
Sijin Joseph http://www.indiangeek.net http://weblogs.asp.net/sjoseph
Jon Pope wrote: I've got a basic question about threading which I'm hoping someone here will be able to answer:
Let's say my calling CallingClass has instantiated and started a worker thread. When my worker thread has completed, it fires an event which CallingClass has an event handler listening for.
My question is this: in which thread is that event handler operating? The worker's or CallingClass's? The issue I'm running into is that if I include a Worker.Join() call within the event handler on CallingClass, it just sits there forever waiting for the worker thread to stop.
Is this even the proper to signal the end of a thread? I have some processing that is waiting for the thread is completely finish and shutdown, and I need a way to find that out. Any help someone can provide would be greatly appreciated.
Cheers, Jon
Thanks, Patty, I appreciate your help. Just so I'm clear: what you're
suggesting is that I pass in a delegate to my Worker thread which points to
a subroutine within my CallingClass. This subroutine is what I want to call
from within my thread when it's done. Is this accurate?
Jon
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com... If you are using (or there is a possibility that you will be using) the CallingClass as part of a user interface, then when you want the worker to 'fire an event' that will tell the calling class that the worker is finished, you should really transfer control back to the thread that the calling class is running in, to ensure this happens, you need to use a delegate which you invoke by calling the BeginInvoke method of the calling class (you might need to derive CallingClass from something in order to do this). It's probably a good idea to do this anyway, as it enables you to be sure that the boundary between classes is the same as the boundary between threads, and you haven't got a thread 'calling into' another thread's class.
"Jon Pope" wrote:
I've got a basic question about threading which I'm hoping someone here will be able to answer:
Let's say my calling CallingClass has instantiated and started a worker thread. When my worker thread has completed, it fires an event which CallingClass has an event handler listening for.
My question is this: in which thread is that event handler operating? The worker's or CallingClass's? The issue I'm running into is that if I include a Worker.Join() call within the event handler on CallingClass, it just sits there forever waiting for the worker thread to stop.
Is this even the proper to signal the end of a thread? I have some processing that is waiting for the thread is completely finish and shutdown, and I need a way to find that out. Any help someone can provide would be greatly appreciated.
Cheers, Jon
Not quite, nearly though.
inline
"Jon Pope" wrote: Thanks, Patty, I appreciate your help. Just so I'm clear: what you're suggesting is that I pass in a delegate
When I do it, I don't pass the delegate in. Rather, I define it outside of
both classes (or within one of them if you want, it makes it like a nested
class) but anyway it doesn't need to be a class member. A delegate is a thing
in its own right - where you define it depends on how you want to organise
your project conceptually.
to my Worker thread which points to a subroutine within my CallingClass. This subroutine is what I want to call from within my thread when it's done. Is this accurate?
It only points to the method once it's instantiated. Don't forget delegates
have a type definition and an instantiation just like classes. IMHO, they
should be instantiated on one line of code, which also tells them (for the
first and only time) what method they point to, and invoked on the next,
thereafter, they're forgotten and the instance of the delegate goes out of
scope.
Remember it's completely fine for the worker thread to hold a variable
reference to the main form which is operating in another (the primary)
thread, as long as the only method it calls on it is BeginInvoke, in order to
transfer control back to the primary thread.
Jon
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message news:55**********************************@microsof t.com... If you are using (or there is a possibility that you will be using) the CallingClass as part of a user interface, then when you want the worker to 'fire an event' that will tell the calling class that the worker is finished, you should really transfer control back to the thread that the calling class is running in, to ensure this happens, you need to use a delegate which you invoke by calling the BeginInvoke method of the calling class (you might need to derive CallingClass from something in order to do this). It's probably a good idea to do this anyway, as it enables you to be sure that the boundary between classes is the same as the boundary between threads, and you haven't got a thread 'calling into' another thread's class.
"Jon Pope" wrote:
I've got a basic question about threading which I'm hoping someone here will be able to answer:
Let's say my calling CallingClass has instantiated and started a worker thread. When my worker thread has completed, it fires an event which CallingClass has an event handler listening for.
My question is this: in which thread is that event handler operating? The worker's or CallingClass's? The issue I'm running into is that if I include a Worker.Join() call within the event handler on CallingClass, it just sits there forever waiting for the worker thread to stop.
Is this even the proper to signal the end of a thread? I have some processing that is waiting for the thread is completely finish and shutdown, and I need a way to find that out. Any help someone can provide would be greatly appreciated.
Cheers, Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anthony_Barker |
last post by:
I have been reading a book about the evolution of the Basic
programming language. The author states that Basic - particularly
Microsoft's version is full of compromises which crept in along the...
|
by: Jane Austine |
last post by:
As far as I know python's threading module models after Java's.
However, I can't find something equivalent to Java's interrupt and
isInterrupted methods, along with InterruptedException....
|
by: David Harrison |
last post by:
I am working on an application on Mac OS X that calls out
to python via PyImport_ImportModule(). I find that if
the imported module creates and starts a python thread,
the thread seems to be...
|
by: Antal Rutz |
last post by:
Hi, All!
I'm new to threading. I have some design questions:
Task: I collect data and store them in an RDBMS (mysql or pgsql)
The question is how to do that with threading?
The...
|
by: CK |
last post by:
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service...
|
by: Anthony Nystrom |
last post by:
What is the correct way to stop a thread? abort? sleep? Will it start up
again... Just curious... If the thread is enabling a form, if the form is
disposed is the thread as well?
Thanks,
...
|
by: Bob |
last post by:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done?
- It is OK to pass objects out of the thread? (dumb question maybe but I
want to be sure)
- What's the best way to...
|
by: DBC User |
last post by:
I have a background process which reads a table to see if there are any
pending requests. If there are any, then it will start a worker thread
(only 10 allowed at a time) and executes a method. In...
|
by: Steven |
last post by:
I am taking an "advanced" VB.Net course via web at a state university
toward an information science degree. This is my second VB class and
I am kind of disappointed in it. This week we covered...
|
by: frankiespark |
last post by:
Hello all,
I was perusing the internet for information on threading when I came
across this group. Since there seems to be a lot of good ideas and
useful info I thought I'd pose a question.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
| |