开发者

Backgroundworker runworkercompleted not firing

I have a really weird problem with background worker. Code is too complicated so will try and explain the problem just want to know if anyone has seen something similar. We have the UI thread spinning off a background thread The background thread does some printing to a pdf printer in the background When finished it just dies as in the thread function exits and so I expect the runworkercompleted event to be raised

this is win forms .NET 2.0

So every time we do a fresh install of the product and fire up our app the runworkercompleted even is not getting fired if we kill our app from task 开发者_StackOverflowmanager and start over it works like a charm ( naturaly we are a little concerned that the first thing a user sees with our product is a hang :-) )

Logging has confirmed that in every case i) The background worker thread function does exit cleanly ii) No exceptions are raised in said thread func

This is 100% reproable on two machine one a win7 and one Vista Sp1. its really, I cannot understand what the first time run has to do with it

Any suggestions welcome


I was having this problem when I realized that I was disposing of my BackgroundWorker object and detaching the event handlers too early before the async execution could complete. Look in your code and ensure that you are not surrounding your BackgroundWorker with a using block or specifically calling dispose or otherwise disconnecting your event handlers.


Is the RunWorkerCompleted event actually registered to the BackgroundWorkers event handler?

It may seem almost a sanity check, but that could explain why teh BackgroundWorker exits cleanly, and the RunWorkerCompleted is not fired.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜