進捗レポートを取得しようとしている階層化されたワーカー クラスがあります。私が持っているものは次のようになります。
public class Form1
{
private void Start_Click()
{
Controller controller = new Controller();
controller.RunProcess();
}
}
public class Controller
{
public void RunProcess()
{
Thread newThread = new Thread(new ThreadStart(DoEverything));
newThread.Start();
}
private void DoEverything()
{
// Commencing operation...
Class1 class1 = new Class1();
class1.DoStuff();
Class2 class2 = new Class2();
class2.DoMoreStuff();
}
}
public class Class1
{
public void DoStuff()
{
// Doing stuff
Thread.Sleep(1000);
// Want to report progress here
}
}
public class Class2
{
public void DoMoreStuff()
{
// Doing more stuff
Thread.Sleep(2000);
// Want to report progress here as well
}
}
以前に BackgroundWorker クラスを使用したことがありますが、このようなものにはもう少し自由な形式が必要だと思います。デリゲート/イベント ソリューションを使用できると思いますが、ここで適用する方法がわかりません。クラス1とクラス2の進行状況で更新できるようにしたいフォーム1にいくつかのラベルまたは何かがあるとしましょう。それを行う最良の方法は何ですか?