大家好,
我在程序中,使用了application.idle消息,在消息里面我有一个循环,来检测还有没有消息,可是在我应用的第3方控件操作的时候,判断不出来,造成程序处理慢。 void Application_Idle(object sender, EventArgs e)
{
while (AppStillIdle())
{
if (OnDocumentUpdates != null)
OnDocumentUpdates(this,EventArgs.Empty);
} } private bool AppStillIdle()
{
NativeMethods.Message msg;
return !NativeMethods.PeekMessage(out msg, Handle, 0, 0, 0);
}====================================================== public static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public UInt32 msg;
public IntPtr wParam;
public IntPtr lParam;
public UInt32 time;
public Point p;
} [SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
}
我在程序中,使用了application.idle消息,在消息里面我有一个循环,来检测还有没有消息,可是在我应用的第3方控件操作的时候,判断不出来,造成程序处理慢。 void Application_Idle(object sender, EventArgs e)
{
while (AppStillIdle())
{
if (OnDocumentUpdates != null)
OnDocumentUpdates(this,EventArgs.Empty);
} } private bool AppStillIdle()
{
NativeMethods.Message msg;
return !NativeMethods.PeekMessage(out msg, Handle, 0, 0, 0);
}====================================================== public static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public UInt32 msg;
public IntPtr wParam;
public IntPtr lParam;
public UInt32 time;
public Point p;
} [SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
}
{
void Application_Idle(object sender, EventArgs e)
{
while (AppStillIdle())
{
if (OnDocumentUpdates != null)
OnDocumentUpdates(this,EventArgs.Empty);
} } private bool AppStillIdle()
{
NativeMethods.Message msg;
return !NativeMethods.PeekMessage(out msg, Handle, 0, 0, 0);
}
}
应用程序启动
{
Application.EnableVisualStyles(); // must be done before creating any forms
Application.SetCompatibleTextRenderingDefault(false); // must be done before creating any forms mainForm = new MainForm();
Application.Run(mainForm);
}
你在里面while处理的话,哪会接到消息呢.
PeekMessage(out msg, Handle, 0, 0, 0);
******
改之后:
PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
^^^^^^^^^^^^