我怎么知道我的工作线程何时完成了他们的任务? [英] How do I know when my work threads have completed their tasks?

查看:85
本文介绍了我怎么知道我的工作线程何时完成了他们的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vs2005和.net 2.0。我启动了2个线程池线程。我怎么知道b
他们完成任务的时间?谢谢。


ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));

ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));

-

谢谢。

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.

推荐答案

嗨Pucca,


WaitCallBack-handler(例如PopulateContextTable)应该在

处发出信号,并且可能在finally块中。如果从GUI-Thread调用它,你可以在其中一个Forms方法上调用BeginInvoke。


Christof


Pucca < Pu *** @ discussion.microsoft.comschrieb im Newsbeitrag

新闻:E8 ************************* ********* @ microsof t.com ...
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.comschrieb im Newsbeitrag
news:E8**********************************@microsof t.com...

我正在使用vs2005和.net 2.0。我启动了2个线程池线程。怎么

我知道他们完成任务后会知道吗?谢谢。


ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));

ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));

-

谢谢。
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.



谢谢Christof。这两个线程在一个表单中作为worker

线程启动。在这种形式下,它们被编码为2静态方法。 2

线程没有自己的形式。我怎么能知道他们什么时候完成他们的任务?

-

谢谢。

Christof Nordiek写道:
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:

您好Pucca,


WaitCallBack-handler(PopulateContextTable例如)应该在
$发出信号b $ b the,也许是最后一块。如果从GUI-Thread调用它,你可以在其中一个Forms方法上调用BeginInvoke。


Christof


Pucca < Pu *** @ discussion.microsoft.comschrieb im Newsbeitrag

新闻:E8 ************************* ********* @ microsof t.com ...
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.comschrieb im Newsbeitrag
news:E8**********************************@microsof t.com...

我正在使用vs2005和.net 2.0。我启动了2个线程池线程。怎么

我知道他们完成任务后会知道吗?谢谢。


ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));

ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));

-

谢谢。
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.






在线程上使用Join方法。但是,有一个小的问题:如果你在UI线程中调用Join,那么你就会挂起UI。


通常的解决方案是使用两个线程中的一个作为控制器,

或使用第三个线程。在第一种情况下,第二个线程是

启动时可以提交第一个线程的引用,并在它发出信号表明它已完成之前执行Join

。如果第一个线程还没有完成,那么第二个线程将在Join上等待,直到它为止。

因此,当第二个(控制器)线程是完了,你知道

他们两个都完成了。


如果这两个线程在逻辑上不相关,那么它可能是

更好地使用第三个控制器线程:UI启动控制器,

然后启动两个工作线程。然后控制器执行两个

连接,每个工作线程一个,当两个连接完成时,它会向UI发出信号,告知UI完成所有操作。这可以扩展到任意数量的工作线程。


1月26日上午10点35分,Pucca< P ... @讨论。 microsoft.comwrote:
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.comwrote:

谢谢Christof。这两个线程在一个表单中作为worker

线程启动。在这种形式下,它们被编码为2静态方法。 2

线程没有自己的形式。我怎么能知道他们什么时候完成他们的任务?

-

谢谢。


" Christof Nordiek"写道:
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:

你好Pucca,
Hi Pucca,


WaitCallBack-handler(PopulateContextTable例如)应该发信号表示

和,也许是在最后一个块中。如果从GUI-Thread调用它,那么
可以在其中一个Forms方法上调用BeginInvoke。
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
Christof


" Pucca" < P ... @ discussion.microsoft.comschrieb im Newsbeitrag

新闻:E8 ************************* ********* @ microsof t.com ...
"Pucca" <P...@discussions.microsoft.comschrieb im Newsbeitrag
news:E8**********************************@microsof t.com...

我正在使用vs2005和.net 2.0。我启动了2个线程池线程。怎么

我知道他们完成任务后会知道吗?谢谢。
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.-隐藏引用文本 - 显示引用文本 -
ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateContextTable));
ThreadPool.QueueUserWorkItem(new WaitCallback(PopulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -


这篇关于我怎么知道我的工作线程何时完成了他们的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆