我有一个C#WinForms应用程序,我想异步调用Application.Run()
所以我可以在启动win表单后添加更多代码到Program.Main()
。所以我修改了class Program
如下:
delegate void AsyncRunCaller(Form form);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1()); // original code
// async call to Application.Run()
AsyncRunCaller caller = new AsyncRunCaller(Application.Run);
IAsyncResult result = caller.BeginInvoke(new Form1(), null, null);
// PROBLEM: Form1 is not shown at this point.
// More code to be added here to run in parallel to Form1
caller.EndInvoke(result); // Form1 is only shown after executing this line.
}
我想知道是否有办法实现这一目标,还是我采取了错误的做法?