If you don’t need very fine control over stream processing, you can use BackgroundWorker instead . It processes the entire data transmission on several channels. You basically put your background code in a DoWork event handler, and then pass the data back to the user interface stream through the ProgressChanged and RunWorkerCompleted events. The link above provides a complete example of how to use it.
, , . , , . , BackgroundWorker.
, . , , , , .
class MyClass {
public event EventHandler SomethingHappened;
protected virtual void OnSomethingHappened(EventArgs e) {
EventHandler handler = SomethingHappened;
if (handler != null) {
handler(this, e);
}
}
public void DoSomething() {
OnSomethingHappened(EventArgs.Empty);
}
}