代表宣布:
public delegate void SampleDelegate(string msg);
表单类中的可调用方法:
...
var sampleNotify = new SampleDelegate(NotifyMe);
//передаю делегат
...
public void NotifyMe(string displayedString)
{
Logger.Info("Зашли в NotifyMe с " + displayedString + "%");
textBox1.Text = displayedString;
//Application.DoEvents(); - пробовал вызывать
}
日志显示NotifyMe所需的行已进入,但textBox1其中没有任何内容。NetFramework 4.0
确保您的委托在窗体的 UI 线程上同步运行。否则(异步),必须通过同步上下文访问控件: