本文整理汇总了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;
});
}