【发布时间】:2014-11-07 15:53:57
【问题描述】:
我正在维护 voip 多线程 windows 窗体应用程序,我可以理解当我们不想定义委托但想使用委托将数据从工作线程路由到 gui 线程时使用 MethodInvoker,因此这段代码有意义
void Synch_ProgressComplete(bool Success)
{
_SynchPseudoGauge = 100;
if (this.InvokeRequired)
this.Invoke((MethodInvoker)
(() => { SynchProgressBar.Value = _SynchPseudoGauge; }));
else
SynchProgressBar.Value = _SynchPseudoGauge;
_LastSynchAvailability = _Synch.Available;
if (this.InvokeRequired)
this.Invoke((MethodInvoker)
(() => { WebserviceAvailibilityLabel.ForeColor = Success ? Color.Black : Color.Red; }));
else
WebserviceAvailibilityLabel.ForeColor = Success ? Color.Black : Color.Red;
if (this.InvokeRequired)
this.Invoke((MethodInvoker)
(() => { WebserviceAvailibilityLabel.Text = Success ? "Webservice Available" : "Webservice Error"; }));
else
WebserviceAvailibilityLabel.Text = Success ? "Webservice Available" : "Webservice Error";
但我不明白这一点
SynchroniseDelegate SynchDelegate = new SynchroniseDelegate(_Synch.Synchronise);
AsyncCallback SynchCallback = new AsyncCallback(Synch_Callback);
AsyncCallback SynchCallback = new AsyncCallback(Synch_Callback);
SynchDelegate.BeginInvoke(Synchronisation.ForceSync.All, SynchCallback, new object() { });
private void Synch_Callback(IAsyncResult ar)
{
this.Invoke(new MethodInvoker(InitialiseTelephony), new object() { });
}
谁能帮忙
【问题讨论】:
-
还有什么不懂的?
-
你有什么不明白的?你了解的sn-ps似乎和你不了解的没有什么不同。
-
为什么 new 运算符与 MethodInvoker 一起使用,而在上面的代码中 MethodInvoker 没有使用 new 运算符
-
@Servy 为什么 new 运算符与 MethodInvoker 一起使用,而在上面的代码中 MethodInvoker 没有使用 new 运算符
-
Control.BeginInvoke() 和委托的 BeginInvoke() 方法完全不相关,并且做的事情非常不同。 this post的一些背景。
标签: c# multithreading asynchronous delegates