Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How do I know when my work threads have completed their tasks?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pucca  
View profile  
 More options Jan 26 2007, 11:22 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Fri, 26 Jan 2007 08:22:00 -0800
Subject: How do I know when my work threads have completed their tasks?
Hi, I'm using vs2005 and .net 2.0.  I started 2 threadpool threads.  How do I
know when they're done with their tasks?  Thanks.

ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));
ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));
--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christof Nordiek  
View profile  
 More options Jan 26 2007, 11:54 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Christof Nordiek" <c...@nospam.de>
Date: Fri, 26 Jan 2007 17:54:10 +0100
Local: Fri, Jan 26 2007 11:54 am
Subject: Re: How do I know when my work threads have completed their tasks?
Hi Pucca,

the WaitCallBack-handler (PopulateContextTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.

Christof

"Pucca" <Pu...@discussions.microsoft.com> schrieb im Newsbeitrag
news:E805594F-654D-4932-A062-01962A077D10@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pucca  
View profile  
 More options Jan 26 2007, 1:35 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Fri, 26 Jan 2007 10:35:00 -0800
Subject: Re: How do I know when my work threads have completed their tasks?
Thank you Christof.  These 2 threads are started within a form as worker
threads only.  They are coded as 2 static method within this form.  The 2
threads have no form of its own.  How can I then find out when they're both
done with their tasks?
--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bruce Wood  
View profile  
 More options Jan 26 2007, 3:19 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Bruce Wood" <brucew...@canada.com>
Date: 26 Jan 2007 12:19:59 -0800
Local: Fri, Jan 26 2007 3:19 pm
Subject: Re: How do I know when my work threads have completed their tasks?
You use the Join method on the threads. However, there's a small
problem: if you call Join in the UI thread, then you hang the UI.

The usual solution is to use one of the two threads as a "controller",
or use a third thread. In the first case, the second thread to be
started can be handed a reference to the first thread, and do a Join
before it signals that it's finished. If the first thread isn't
finished yet, then the second thread will wait on the Join until it is.
Therefore, when the second (controller) thread is finished, you know
that they're both finishes.

If the two threads are not logically related this way, then it might be
nicer to use a third, controller thread: the UI starts the controller,
which then starts the two worker threads. The controller then does two
Joins, one on each worker thread, and when the two Joins complete, it
signals the UI that all is done. This is scalable to an arbitrary
number of worker threads.

On Jan 26, 10:35 am, Pucca <P...@discussions.microsoft.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pucca  
View profile  
 More options Jan 26 2007, 5:03 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Fri, 26 Jan 2007 14:03:00 -0800
Subject: Re: How do I know when my work threads have completed their tasks?
Thank you.  

I now need to return SearchResultCollection from both the thread.  But I'm
getting error that my code calling the thread has the wrong return
type.ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));  

I have declared my thread method as
static SearchResultCollection PopulatAdTabe(object stateInfo)
{}

Is there something wrong with my declaration?  Thanks.
--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pucca  
View profile  
 More options Jan 31 2007, 5:08 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Wed, 31 Jan 2007 14:08:00 -0800
Subject: Re: How do I know when my work threads have completed their tasks?
I'm using threadpool so I used AutoeventReset and it worked.  Thank you very
much.
--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Kelly  
View profile  
 More options Jan 31 2007, 5:20 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Barry Kelly <barry.j.ke...@gmail.com>
Date: Wed, 31 Jan 2007 22:20:27 +0000
Local: Wed, Jan 31 2007 5:20 pm
Subject: Re: How do I know when my work threads have completed their tasks?

Pucca wrote:
> I'm using threadpool so I used AutoeventReset and it worked.  Thank you very
> much.

Be careful: many uses of AutoResetEvent have a race condition, where the
event is signaled before anything waits on it, thus causing deadlock
when threads do start waiting on it, having "missed the bus", as it
were.

-- Barry

--
http://barrkel.blogspot.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Mullins [MVP]  
View profile  
 More options Jan 31 2007, 5:19 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Chris Mullins [MVP]" <cmull...@yahoo.com>
Date: Wed, 31 Jan 2007 14:19:43 -0800
Local: Wed, Jan 31 2007 5:19 pm
Subject: Re: How do I know when my work threads have completed their tasks?
AutoResetEvent there is pretty scary. If your "are you done yet?" thread
isn't waiting already, then it's going to miss the fact that your work item
is complete. This means the order you do things in is very important, and
(worse) is also hard to get right.

You would be better served, I suspect, using a ManualResetEvent. This
eliminates the problem, and makes your code less likley to have race
conditions.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins

"Pucca" <Pu...@discussions.microsoft.com> wrote in message

news:89FCB56F-0EF0-42EB-A5F1-8D80B59B0657@microsoft.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William Stacey [C# MVP]  
View profile  
 More options Jan 31 2007, 5:52 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "William Stacey [C# MVP]" <william.sta...@gmail.com>
Date: Wed, 31 Jan 2007 17:52:02 -0500
Local: Wed, Jan 31 2007 5:52 pm
Subject: Re: How do I know when my work threads have completed their tasks?
I always enjoy seeing how I might do the same thing when using my
concurrency library.
This is actually a pretty common pattern (i.e. scatter/gather).  I sample
this pattern here
http://www.codeplex.com/PCR/Thread/View.aspx?ThreadId=3459

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject

"Pucca" <Pu...@discussions.microsoft.com> wrote in message

news:89FCB56F-0EF0-42EB-A5F1-8D80B59B0657@microsoft.com...
| I'm using threadpool so I used AutoeventReset and it worked.  Thank you
very
| much.
| --
| Thanks.
|
|
| "Bruce Wood" wrote:

|
| > You use the Join method on the threads. However, there's a small
| > problem: if you call Join in the UI thread, then you hang the UI.
| >
| > The usual solution is to use one of the two threads as a "controller",
| > or use a third thread. In the first case, the second thread to be
| > started can be handed a reference to the first thread, and do a Join
| > before it signals that it's finished. If the first thread isn't
| > finished yet, then the second thread will wait on the Join until it is.
| > Therefore, when the second (controller) thread is finished, you know
| > that they're both finishes.
| >
| > If the two threads are not logically related this way, then it might be
| > nicer to use a third, controller thread: the UI starts the controller,
| > which then starts the two worker threads. The controller then does two
| > Joins, one on each worker thread, and when the two Joins complete, it
| > signals the UI that all is done. This is scalable to an arbitrary
| > number of worker threads.
| >
| > On Jan 26, 10:35 am, Pucca <P...@discussions.microsoft.com> wrote:
| > > Thank you Christof.  These 2 threads are started within a form as
worker
| > > threads only.  They are coded as 2 static method within this form.
The 2
| > > threads have no form of its own.  How can I then find out when they're
both
| > > done with their tasks?
| > > --
| > > Thanks.
| > >
| > >
| > >
| > > "Christof Nordiek" wrote:
| > > > Hi Pucca,
| > >
| > > > the WaitCallBack-handler (PopulateContextTable e.g.) should signal
that at
| > > > the and, maybe in a finally block. If this is called from a
GUI-Thread you
| > > > could call BeginInvoke on one of the Forms methods.
| > >
| > > > Christof
| > >
| > > > "Pucca" <P...@discussions.microsoft.com> schrieb im Newsbeitrag
| > > >news:E805594F-654D-4932-A062-01962A077D10@microsoft.com...
| > > > > Hi, I'm using vs2005 and .net 2.0.  I started 2 threadpool
threads.  How
| > > > > do I
| > > > > know when they're done with their tasks?  Thanks.
| > >
| > > > > ThreadPool.QueueUserWorkItem(new
WaitCallback(PopulateContextTable));
| > > > > ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));
| > > > > --
| > > > > Thanks.- Hide quoted text -- Show quoted text -
| >
| >

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pucca  
View profile  
 More options Feb 6 2007, 5:18 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Tue, 6 Feb 2007 14:18:03 -0800
Local: Tues, Feb 6 2007 5:18 pm
Subject: Re: How do I know when my work threads have completed their tasks?
I think the AutoResetEvent is now cuasing a problem for my code.  
1.  I dind't find good examples on how to code with manualResetEvent, can
you recommend a example on line?  
2.  Do I need to change my program.cs code's [STAThread] to something else?  
Is this the Single thread meaning?

--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pucca  
View profile  
 More options Feb 6 2007, 5:28 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: Pucca <Pu...@discussions.microsoft.com>
Date: Tue, 6 Feb 2007 14:28:05 -0800
Local: Tues, Feb 6 2007 5:28 pm
Subject: Re: How do I know when my work threads have completed their tasks?
Here is my code where I'm having problem with.  It seems like
"ThreadPool.QueueUserWorkItem(new WaitCallback (PopulatContextUsersTable),
contextUserEvent);
"  is being executed before the waiting for the 1st 3 threads are done.  Is
there something wrong with my code or it's the problem with the
AutoResetEvent?

Also, would it be better for me to use the BackgrounWorder class?  Can this
be used for muliple threads as I need it in my code?  Thank you.

private void GenerateDataForComputerDetailReport()
{

AutoResetEvent autoEvent = new AutoResetEvent (false), contextEvent = new
AutoResetEvent (false),
adUserEvent =

new AutoResetEvent(false ), contextUserEvent = new AutoResetEvent(false );

try
{

dsReport.Tables[

"PadComputers"].Clear();
dsReport.Tables[

"AdComputers"].Clear();

switch(reportName)
{

case "Computer Detail":

ThreadPool.QueueUserWorkItem(new WaitCallback
(PopulateContextComputerTable), contextEvent);

ThreadPool.QueueUserWorkItem(new WaitCallback (PopulatAdComputersTable),
autoEvent);
contextEvent.WaitOne();

autoEvent.WaitOne();

if (dsReport.Tables["PAdComputers"].Rows.Count == 0 ||
dsReport.Tables[

"AdComputers"].Rows.Count == 0)

return;
CreateComputersTable();

break;

case "Computer Users Detail":

ThreadPool.QueueUserWorkItem(new WaitCallback (PopulatAdUsersTable),
adUserEvent);

ThreadPool.QueueUserWorkItem(new WaitCallback
(PopulateContextComputerTable), contextEvent);

ThreadPool.QueueUserWorkItem(new WaitCallback (PopulatAdComputersTable),
autoEvent);
contextEvent.WaitOne();

autoEvent.WaitOne();

if (dsReport.Tables["PAdComputers"].Rows.Count == 0 )

return;
CreateComputersTable();

adUserEvent.WaitOne();

ThreadPool.QueueUserWorkItem(new WaitCallback (PopulatContextUsersTable),
contextUserEvent);

//Let's get the current computer name
contextUserEvent.WaitOne();

//After we create the Context user table then proceed
CreateComputerUsersTable();

break;

}

//end switch

}

//end try

catch (Exception ex)
{

MessageBox.Show(ex.ToString());

}

--
Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google