我认为您的问题是,在引发事件时,处理HTTP请求的线程被终止。
如果你想要一些定期的反馈发送给用户,你可以看看信号器。
public class DoingProcessing
{
public Progress<int> HeavyTaskProgress { get; set; }
private void Progress_ProgressChanged(object sender, int e)
{
string message = string.Format("progress at {0}%{1}", e, Environment.NewLine);
System.IO.File.AppendAllText(@"d:\progress.txt", message);
}
public void DoProcessing()
{
HeavyTaskProgress = new Progress<int>();
HeavyTaskProgress.ProgressChanged += Progress_ProgressChanged;
DoProcessing(HeavyTaskProgress);
}
private void DoProcessing(IProgress<int> progress)
{
for (int i = 1; i <= 10; ++i)
{
Thread.Sleep(1000); // CPU-bound work
if (progress != null)
progress.Report(i*10);
}
}
public void ProcessingFinished(Task t)
{
System.IO.File.AppendAllText(@"d:\progress.txt", "Task done !! " + t.Status);
}
public DoingProcessing()
{
}
}