c# Background worker class

北城以北 提交于 2019-12-06 11:22:55

It seems your problem is returning the value from the BackgroundWorker. That can be done like this:

In the worker's DoWork method, set the e.Result to what you want to return:

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{   
    ...
    e.Result = File;
}

Then, in the RunWorkerCompleted method, you can access this value in the main thread:

private void backgroundWorker1_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e)
{
    string result = e.Result as string;
}

I have assumed that File is string here, but you can cast it to your required object.

Why you need it in a web application I have no clue, but this is how to do it at least ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!