使用dispatcher.BeginInvoke时,何时/为什么需要调用Dispatcher.Run?

| 另外,如果我将this.dispatcher与另一个BeginInvoke重用,是否还需要\“ Dispatcher.Run \”?
 var thread = new Thread(() =>
            {
                this.dispatcher = Dispatcher.CurrentDispatcher;
                this.dispatcher .BeginInvoke(new Action(() =>
                {
                    try
                    {
                       do something
                    }
                    catch (Exception ex)
                    {
                        onNotify(ex);
                    }
                }));
                Dispatcher.Run();
            });
            thread.Name = string.Format(\"{0} Hook Thread\", this.GetType().Name);
            thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
    
已邀请:
        
Dispatcher.BeginInvoke
将代表添加到调度程序的事件队列中。 仅在
Run()
内部处理队列。
Run()
是一个阻止调用,它将永久执行(或直到您致电
InvokeShutdown()
)。 如果再次调用
BeginInvoke()
Run()
将立即看到新的委托并立即执行。 (或尽快免费)     

要回复问题请先登录注册