110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace FormThread
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form1 = new Form1();
Thread tempThread = new Thread(new ThreadStart(form1.Show));
tempThread.Start();
while (true)
{
// other code
}
}
}
}
[STAThread]
static void Main()
{
Form2 f = new Form2();
fHandle = f.Handle;
System.Threading.Thread tempThread = new System.Threading.Thread(new System.Threading.ThreadStart( aaa));
tempThread.Start();
f.ShowDialog();
Application.Run(new Form1());
}
static IntPtr fHandle;
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi, SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private static void aaa()
{
System.Threading.Thread.Sleep(6000);
PostMessage(fHandle, 0x0010, IntPtr.Zero, IntPtr.Zero);
}
[STAThread]
static void Main()
{
System.Threading.Thread tempThread = new System.Threading.Thread(new System.Threading.ThreadStart(aaa));
tempThread.Start();
f = new Form2();
f.ShowDialog();
Application.Run(new Form1());
}
static Form2 f;
private static void aaa()
{
System.Threading.Thread.Sleep(6000);
//把你那费时间的代码写在这里来替换System.Threading.Thread.Sleep(6000);
f.Close();
}