模态形式不恢复后最小化2个UI线程
本文关键字:最小化 2个 UI 线程 恢复 模态 | 更新日期: 2023-09-27 18:05:12
问题是,我有一些闪屏显示加载动画。我有专门的经理来显示和隐藏它。
class Manager
{
private Form CurForm;
Thread curt;
private Manager()
{
curt= new Thread(start);
curt.ApartmentState = ApartmentState.STA;
curt.IsBackground = true;
curt.Start();
}
void start()
{
CurForm = new Animation();
Application.Run(CurForm);
}
public static readonly Manager Active = new Manager();
public static void Show()
{
if (Active.CurForm != null)
{
Active.CurForm.Invoke(new Action(() => { Active.CurForm.Show(); }));
}
}
public static void Hide()
{
if (Active.CurForm != null)
{
Active.CurForm.Invoke(new Action(() => { Active.CurForm.Hide(); }));
}
}
}
我打开一些模态形式(ShowDialog)。这个模态表单不会显示在任务栏上。
我可以很容易地最小化它,点击任务栏上的主表单后,它显示在顶部的模态表单。
但是当我显示加载动画时它正在加载所有必要的数据
一些类似的(当然这只是一个例子来测试它的工作,在实际的应用程序中,它需要很多时间来加载所有的数据和表单与大量的控件)
public modal()
{
Manager.Show();
InitializeComponent();
Thread.Sleep(5000);
Manager.Hide();
}
当我试图最小化和恢复它,就像我上面说的,它不恢复我的模态形式,只是显示我的主要不可用的形式。不仅如此,它在某些情况下起作用,但在某些情况下不起作用。
有谁知道为什么会发生或者如何修复它吗?
这很奇怪,但是当我这样修改时,一切似乎都正常了。
我只是杀死单独的ui线程。
public class MyApplicationContext:ApplicationContext
{
public Form CurForm;
ManualResetEvent ready = new ManualResetEvent(false);
public MyApplicationContext()
{
CurForm=new Animation();
CurForm.Show();
}
}
class Manager
{
private MyApplicationContext CurContext;
Thread curt;
void start()
{
try
{
CurContext = new MyApplicationContext();
Application.Run(CurContext);
}
catch
{
CurContext.CurForm.Close();
}
}
private void Init()
{
curt = new Thread(start);
curt.SetApartmentState(ApartmentState.STA);
curt.IsBackground = true;
curt.Start();
}
public static Manager Active
{
get
{
if (active == null)
{
active = new Manager();
}
return active;
}
}
private static Manager active;
public static void Show()
{
Active.Init();
}
public static void Hide()
{
Active.curt.Abort();
}