1

我有一个后台工作程序,当PhoneApplicationPageLoaded.

如何将 _DoWork 过程中生成的列表传输到 _RunWorkerComplete 过程?

这是空代码:(我会把它全部放进去,但它很长)

private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker bw = new BackgroundWorker();
        bw.WorkerReportsProgress = false;
        bw.WorkerSupportsCancellation = false;

    bw.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
    }

private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {

    }
4

1 回答 1

2

Set e.Result in the DoWork handler and read e.Result in the RunWorkerCompleted handler (you'll need to cast it back to the appropriate type).

Other options are to use an instance field of the type; set it in one and read it in the other, or to have both event handlers being lambdas, rather than named methods, in which they both close over some common variable(s).

于 2013-07-22T18:54:10.487 回答