开发者

C# ThreadPool or BeginInvoke without EndInvoke

On the net there a very different opinions on how to implement a fire and forget pattern.

Some say that it is no issue to call BeginInvoke without calling EndInvoke if one has to implement a fire-and-forget pattern.

Others say it's better to create a separate ThreadPool object. My concern is about the ThreadPool initialization cost. Specifically, the the method to call does only add an object to a queue and then returns.

For this, is it "faster" to create a thread on the pool or simply to call the method synchronously? I would like to know a rough threshold of work which is more expensive than to create the thread on the pool.

Are there any 开发者_JAVA技巧documentations on this and what about exception catching on the pool and other restcritions with it?


When using the ThreadPool you do not "create the thread on the pool", you use a pre-existing Thread or wait until one comes available.

Only when many jobs are waiting the Pool will add another Thread, but then that one will be well utilized.

Even better to use Tasks (Fx4 and higher).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜