Equivalent to InvokeRequired in WPF

前端 未结 4 1207
醉酒成梦
醉酒成梦 2021-02-15 22:40

Is there an equivalent to Form.InvokeRequired in WPF, e.g. Dispatcher.InvokeRequired?

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 23:18

    A possible solution that came to mind is:

    if ( Dispatcher.Thread.Equals( Thread.CurrentThread ) )
    {
        Action( );
    }
    else
    {
        Dispatcher.Invoke( Action );
    }
    

提交回复
热议问题