我通常使用BackgroundWorker:
void ProcessWithBackgroundWorker()
{
var worker = new BackgroundWorker();
worker.DoWork += delegate (object o1, DoWorkEventArgs e1)
{
// my code
};
worker.RunWorkerCompleted += delegate (object o2, RunWorkerCompletedEventArgs e2)
{
// my code
};
worker.RunWorkerAsync();
}
这没有引起问题;工作在后台执行,可能需要很长时间才能运行。但是worker
退出范围之后是什么让ProcessWithBackgroundWorker
实例保持活着?