ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));
ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));
--
Thanks.
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...@microsoft.com...
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...@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 -
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.
> 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
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...@microsoft.com...
--
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...@microsoft.com...
--
Thanks.
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.