[size=medium]wpf主进程信号处理[/size]
public partial class Login : UserControl
{
public static EventWaitHandle ProgramStarted;
public Login()
{
InitializeComponent();
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset);
ThreadPool.RegisterWaitForSingleObject(ProgramStarted, OnProgramStarted, null, -1, false);
}
private void OnProgramStarted(object state, bool timeout)
{
Thread thread = new Thread(new ThreadStart(new Action(() =>
{
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate()
{
//chuli
});
})));
//因为是线程池通知主进程,必须在单线程单元ApartmentState.STA执行
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
}
}