问题描述
我们有一个应用程序,它执行从外部
应用程序提交的作业。它通过创建一个可以运行作业的
方法的委托,并在方法上调用BeginInvoke来异步执行它们。
整个工作本身,我们使用CallContext类来存储调用流中许多类所需的信息
。这很好用,并且
并发线程工作正常。
结果是,在完成一个工作后,另一个工作完成后,
有时候,新工作正在与
刚刚完成的工作相同的线程上执行(即,它们具有相同的线程ID)。因此看起来好像
线程正在被后续作业重用 - 因此
CallContext上的信息将从上一个作业(已完成)中遗留下来 - 作为反对被清除。
任何人都知道线程被重用的原因(特别是没有首先清除掉
)这样吗?
Hi, we have an app, that executes jobs submitted from an outside
application. It executes them asynchronusly, by creating a delegate to the
method that can run the job, and calling BeginInvoke on the method.
Throughout the job itself, we use the CallContext class to store information
that is needed by many classes in the call stream. This works well, and
concurrent threads are working fine.
What happens is, that after a job is done, and another one is started,
sometimes, the new job, is being executed on the same thread as the job that
just finished (i.e., they have the same thread id). So it looks like
threads are being reused by subsequent jobs - and so the information on the
CallContext is left over from the previous job (which has completed) - as
opposed to being cleared out.
Anyone know why the threads are being reused (especially without being
cleared out first) in this way?
推荐答案
我不知道清除位,但线程被重用,因为
BeginInvoke使用ThreadPool。这通常是一件非常好的事情,因为创建线程是一项相对昂贵的任务。
-
Jon Skeet - < sk *** @ pobox.com>
如果回复群组,请不要给我发邮件
I don''t know about the clearing bit, but threads are reused because
BeginInvoke uses the ThreadPool. This is usually a very good thing, as
creating threads is a relatively expensive task.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
我不是知道清除位,但线程被重用,因为BeginInvoke使用ThreadPool。这通常是一件非常好的事情,因为创建线程是一项相对昂贵的任务。
- Jon Skeet - < sk *** @ pobox.com>
I don''t know about the clearing bit, but threads are reused because
BeginInvoke uses the ThreadPool. This is usually a very good thing, as
creating threads is a relatively expensive task.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
我不是知道清除位,但线程被重用,因为BeginInvoke使用ThreadPool。这通常是一件非常好的事情,因为创建线程是一项相对昂贵的任务。
- Jon Skeet - < sk *** @ pobox.com>
I don''t know about the clearing bit, but threads are reused because
BeginInvoke uses the ThreadPool. This is usually a very good thing, as
creating threads is a relatively expensive task.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于在委托和线程重用上调用BeginInvoke的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!