Is there a limit to the amount of time a BackgroundWorker
will run without user interaction/change? I left a WPF
program threaded with one running over night and it stopped at some point. I could press the button to trigger DoWork
in the morning and it would start up again.
I'm not yet sure whether it fired RunWorkerCompleted
, I didn't have the event added and it takes a very long time to test, obviously. The worker begins on a button press, and, looping continuously, crawls data and prints it to the GUI.
while (true)
{
//Crawl for data, output to WPF window
}
The loop only exits if cancellation is pending from another button press, which I never pressed.
I'm just curious whether there's some sort of documented timeout for the BackgroundWorker
class.
Further to my comment, you may find that your worker encountered an exception. This wouldnt necessarily make your program crash so try something similar to the following
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error == null)
{
//Worker completed successfully
}
else
{
//An error was thrown
}
}
Theoretically it should run forever. To test if it really died I would consider adding some basic logging. ALso a quick check shows this, which might be what's happening.
BackgroundWorker dies unexpectedly
I would add the RunWorkerCompleted event handling to see if this is the case.
BackgroundWorker does not have/supprort timeout. It is more probable that the thread was killed because of the cpu usage or sth like that.
But first of all do you have some logging mechanism? This is crucial in such operations.
Is the code inside the try..catch
block?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.