473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

threading question

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
Nov 16 '05 #1
3 1970
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

Nov 16 '05 #2
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

Nov 16 '05 #3
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


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
6657
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...
19
6440
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....
3
1482
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...
4
1573
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...
6
555
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...
7
318
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, ...
4
1282
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...
4
321
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...
4
1579
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...
19
1783
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. ...
0
7108
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
6967
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...
1
6847
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...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.