本文整理匯總了C#中System.Windows.Forms.Form.EndInvoke方法的典型用法代碼示例。如果您正苦於以下問題:C# Form.EndInvoke方法的具體用法?C# Form.EndInvoke怎麽用?C# Form.EndInvoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.EndInvoke方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExecuteInThread
private void ExecuteInThread(ThreadStart run)
{
Exception uncaughtException = null;
var thread = new Thread(() =>
{
try
{
run();
}
catch (Exception e)
{
uncaughtException = e;
}
Application.DoEvents();
Application.Exit();
});
var form = new Form();
if (form.Handle == IntPtr.Zero)
{
throw new InvalidOperationException("Control handle could not be obtained");
}
var invoke = form.BeginInvoke((MethodInvoker)thread.Start);
Application.Run();
form.EndInvoke(invoke);
if (uncaughtException != null)
{
preserveStackTrace.Invoke(uncaughtException, null);
throw uncaughtException;
}
}
示例2: CrawlDate
private static async Task<Report> CrawlDate(Form ui, Request request)
{
var completed = new ManualResetEvent(false);
Report r = null;
Action initAction = () =>
{
var crawler = new SkyCrawler();
crawler.Load += async delegate
{
r = await crawler.Analyze(request);
var dates = request.From.ToDateString() + "-" + request.To.ToDateString();
string path = Path.Combine("e:\\Flights", request.Source + "-" + request.Dectination,
dates + ".xml");
Directory.CreateDirectory(Path.GetDirectoryName(path));
r.ToXml(path);
crawler.Close();
completed.Set();
if (r.Data.Length > 0)
{
Console.Out.WriteLine("{0} -> {1}: {2}", dates, request.Dectination, r.Data[0].Price);
}
};
crawler.Show();
};
await Task.Factory.FromAsync(
ui.BeginInvoke(initAction),
x => { ui.EndInvoke(x); });
return await Task.Factory.StartNew(() =>
{
completed.WaitOne();
return r;
});
}