- 积分
- 94
- 在线时间
- 32 小时
- 主题
- 2
- 注册时间
- 2013-8-13
- 帖子
- 61
- 最后登录
- 2024-5-24
- 帖子
- 61
- 软币
- 438
- 在线时间
- 32 小时
- 注册时间
- 2013-8-13
|
using System;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
namespace Jarloo
{
public class WindowManager
{
public static void LaunchWindowNewThread<T>() where T : Window, new()
{
Thread newWindowThread = new Thread(ThreadStartingPoint);
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
Func<Window> f = delegate
{
T win = new T();
return win;
};
newWindowThread.Start(f);
}
private static void ThreadStartingPoint(object t)
{
Func<Window> f = (Func<Window>) t;
Window win = f();
win.Show();
Dispatcher.Run();
}
}
}
WindowManager.LaunchWindowNewThread<MainWindow>();
|
|