- VisualC#
-
2008-01-30 - 更新:2017-02-21
バックグラウンドで処理を実行中、メインスレッドのメソッドを実行したいとき、
通常のようには呼び出せないので、デリゲートを使って呼び出します。
メインスレッド
Thread tMain = new Thread(new ThreadStart(SampleThread)); tMain.IsBackground = true; tMain.Start();
デリゲートの定義
delegate void SampleDelegate(string args);
メソッドの定義
private void SampleMethod(string args)
{
Console.Writeline(args);
}
スレッド
private void StartServer()
{
this.Invoke(new SampleDelegate(this.SampleMethod), "sample text");
}
2,298 views




