//VisualStudio2005 C# を使用してます //やりたいこと //フォームのbutton1から クラスaの関数bを呼ぶ //クラスaの関数bで スレッドcを行う //スレッドcの終了時に フォームの関数dを呼びたい //フォームの関数dで button1.text="e"; としたい。(スレッドcの結果を表示) //困っていること //button1.text="e"; とするときエラーが出る //別スレッドからコントロールを操作できないらしい using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace app2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } a aa=new a(); //クラスa private void button1_Click(object sender, EventArgs e) { a.delegate_dd return_dd = new a.delegate_dd(d); //終了時に呼ばれるメソッド aa.b(return_dd); } //終了時に呼ばれるメソッド void d() { System.Diagnostics.Debug.WriteLine("デバグ eee"); button1.Text = "ee"; //エラー:有効ではないスレッド間の操作: コントロールが作成されたスレッド以外のスレッドからコントロール 'button1' がアクセスされました。 } } class a { public delegate void delegate_dd(); delegate_dd break_call_dd; public void b(delegate_dd break_call_para) { break_call_dd = break_call_para; //処理が終わった時に呼ぶメソッド //メソッドを別のスレッドで実行する System.Threading.Thread cc = new System.Threading.Thread(new System.Threading.ThreadStart(c)); cc.Start(); //スレッドを開始する } public void c() { System.Threading.Thread.Sleep(1000); break_call_dd(); //呼び出し元で指定されたメソッドを呼ぶ //Invoke(break_call_dd()); //エラー回避で元の基本スレッドで実行したい } } }