请教个菜鸟问题 在类中更新窗体上的控件
可以做把form的对象传给类 不过想用委托实现 整半天正不明白了 最好能给个简单的小例子 多谢
------解决方案--------------------
class A
{
public event EventHandler viewProcess;
private void RaiseviewProcess(object sender, EventArgs e)
{
if (viewProcess != null)
{
viewProcess(sender, e);
}
}
private void aaaa()
{
RaiseviewProcess(this,new EventArgs());
}
}
class Form1
{
public Form1()
{
....
A a1= new A();
a1.viewProcess += (o,e) = > { 更新控件代码 };
}
}
------解决方案-------------------- Thread thread1, thread2;
Object obj = new object();
List<ManualResetEvent> mres = new List<ManualResetEvent>();
Task task = new Task();
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
Test();
}
public void Test()
{
task.OnMessageNotice += invokeMsg;
ManualResetEvent mre1 = new ManualResetEvent(false);
mres.Add(mre1);
ManualResetEvent mre2 = new ManualResetEvent(false);
mres.Add(mre2);
thread1 = new Thread(new ParameterizedThreadStart(task.DoWork));
thread2 = new Thread(new Param