The dowork package into a category, I would like to ask how to transfer a return

The function dowork is encapsulated as a class, want to run bw_RunWorkerCompleted, a return parameter passed to instantiate the caller, excuse me this how to write it, please advice. Got a few days didn't understand this principle, ha ha, feel really stupid.

public class DoWorkClass;
{
private BackgroundWorker bw;
private string Progress;
public void BackgroundInitialization()
{
bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork +=new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged +=new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted +=new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
}
public void startDoWork()
{
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
}
public void CancelDoWork()
{
if (bw.WorkerSupportsCancellation == true)
{
bw.CancelAsync();
}
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;

int i = 0;
foreach (ExpressSignTable c in lstUpdateSign)
{
i++;
worker.ReportProgress(i*100 / lstUpdateSign.ToList().Count);
}
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{

}
private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Progress = (e.ProgressPercentage.ToString()+ "%");
}
}
}

Started by Harold at December 10, 2016 - 6:17 PM

bw.DoWork +=new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged +=new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted +=new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

You use so much class event, will not give their class with an event?

Posted by Hogan at December 20, 2016 - 6:37 PM

Learn about delegate, event

Posted by Humphrey at December 30, 2016 - 7:27 PM

I think you mean to discuss the background process and the foreground process data interaction. In fact, Microsoft logic is on the event, trust model to do.
A need to transfer data using EVENTARGS e to do. But the processing function you this event RunWorkerCompleted and no action, so the data is not spread out.
Two your agency design adhering to this class and the Microsoft differ. You say "transfer to instantiate the caller a return parameter" so this required in your RunWorkerCompleted, an interface instance caller to pass parameters. All instantiations of the caller must implement the same interface. But the event delegate logic has no requirements on the caller. You only need to + = or registered on it.

Posted by Jason at January 03, 2017 - 8:10 PM

Thank you so much understanding and guidance, I am from other language over development of Windows Phone, some of the ideological conversion is difficult to understand. If you can, please help me to write an example or give a detailed example for me to learn about it. C# programming and MSDN, and simply said the delegate and event, can't seem to meet the demand of,
I am now in order to use, to write the code inside mainpage.cs, the code and ugly, do not meet the coding principle.

Posted by Harold at January 08, 2017 - 9:03 PM

We recommend that you first look BAIDU C# commissioned, doubt in your question post code up to ask, so higher efficiency, to understand things speak out let everyone understand difficult.

Posted by Jason at January 09, 2017 - 9:18 PM