,代表的定義是:在爲什麼使用委託C#允許線程訪問形式的對象(如文本框)從我讀
委託是一種引用的方法。一旦代表 分配了 方法,它的行爲與該方法完全相同。與任何其他方法一樣,代理方法可以使用 ,並帶有參數和返回值。
現在我知道該怎麼寫,形成對象說,通過螺紋文本框使用委託,但是我不明白這是如何在委託處理的方法可以在表格上訪問 的所有對象。如果有人能夠澄清這一點,我將不勝感激。
編輯: 現在,這裏是我會怎樣創建一個委託
public delegate void MyDelegate(string str,int str2);
void main()
{
Thread t = new Thread(RunInThread); //Method that will run in a separate thread
t.Start();
}
void RunInThread()
{
MyDelegate delInstatnce = new MyDelegate(AddControl); //Attach a method
this.Invoke(delInstatnce,"First Parameter",1001);
}
void AddControl(string str,int str2)
{
//Why could you access all the form components from here ?
}
人們需要停止downvoting的問題,只是因爲提問者在問題的前提混淆。 –