C# 加载程序闪烁不呈现WinForm
我试图运行一个长过程来检索数据,并在检索数据时将加载程序屏幕(简单表单)显示为对话框。我遇到的问题是,当后台工作程序运行时,加载程序屏幕只会闪烁,不会在加载程序窗体中呈现标签。在后台工作运行时,您可以只看到灰色矩形,如下所示 有人知道为什么加载器表单没有显示他们的标签,为什么它会闪烁吗C# 加载程序闪烁不呈现WinForm,c#,winforms,C#,Winforms,我试图运行一个长过程来检索数据,并在检索数据时将加载程序屏幕(简单表单)显示为对话框。我遇到的问题是,当后台工作程序运行时,加载程序屏幕只会闪烁,不会在加载程序窗体中呈现标签。在后台工作运行时,您可以只看到灰色矩形,如下所示 有人知道为什么加载器表单没有显示他们的标签,为什么它会闪烁吗 private void LoadInfo() { try { workingLoader = new WorkingLoader(); mainWorker =
private void LoadInfo()
{
try
{
workingLoader = new WorkingLoader();
mainWorker = new BackgroundWorker();
mainWorker.DoWork += MainWorker_DoWork;
mainWorker.RunWorkerCompleted += MainWorker_RunWorkerCompleted;
mainWorker.RunWorkerAsync();
workingLoader.ShowDialog();
}
catch (Exception ex)
{
if (workingLoader != null)
{
workingLoader.Dispose();
}
}
}
可能在加载时对workingLoader调用Update()?或者将mainWorker移动到workingLoader表单?标签更新的位置和方式?标签是静态的-它基本上说是加载您是否尝试将
双缓冲
设置为真
?我没有看到您订阅?您正在尝试从DoWork
更新这些控件吗?也许,也可以使用.Invoke()
进行闭环操作?mainWorker
如何更新显示为模态的workingLoader
中的控件?
internal static class NativeWinAPI
{
internal static readonly int GWL_EXSTYLE = -20;
internal static readonly int WS_EX_COMPOSITED = 0x02000000;
[DllImport("user32")]
internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32")]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}
And your form constructor should look as follows:
public MyForm()
{
InitializeComponent();
int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
style |= NativeWinAPI.WS_EX_COMPOSITED;
NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
}
In the code above, you might change this.Handle to something like MyFlickeringPanel.Handle