`

wpf主进程信号处理

 
阅读更多
wpf主进程信号处理
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();
        }
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics