本文整理汇总了C#中DoWorkEventHandler.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# DoWorkEventHandler.Invoke方法的具体用法?C# DoWorkEventHandler.Invoke怎么用?C# DoWorkEventHandler.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoWorkEventHandler
的用法示例。
在下文中一共展示了DoWorkEventHandler.Invoke方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WorkInBackground
/// <summary>
/// Executes the work in background to avoid DIS.Presentation.KMT hangs
/// </summary>
protected void WorkInBackground(DoWorkEventHandler work, RunWorkerCompletedEventHandler onCompleted = null)
{
//Getting called from DIS.Presentation.KMT, execute on background worker
if (uiDispatcher != null)
{
using (BackgroundWorker worker = new BackgroundWorker())
{
worker.DoWork += (s, e) =>
{
try
{
Thread.CurrentThread.CurrentUICulture = KmtConstants.CurrentCulture;
Thread.CurrentThread.CurrentCulture = KmtConstants.CurrentCulture;
}
catch (Exception ex)
{
ExceptionHandler.HandleException(ex);
}
work(s, e);
};
if (onCompleted == null)
onCompleted = new RunWorkerCompletedEventHandler((s, e) =>
{
if (e.Result != null)
{
if (!(e.Result is Message))
throw new ApplicationException("Background worker result is invalid.");
Message msg = e.Result as Message;
if (msg != null)
{
ValidationHelper.ShowMessageBox(msg.Content, msg.Title);
}
}
});
worker.RunWorkerCompleted += onCompleted;
worker.RunWorkerAsync();
}
}
//Getting called from unit test, execute on main thread
else
{
work.Invoke(null, new DoWorkEventArgs(null));
}
}