How do I update a Label from within a BackgroundWorker thread?

后端 未结 5 1935
慢半拍i
慢半拍i 2020-12-20 06:59

When I used WinForms, I would have done this in my bg_DoWork method:

status.Invoke(new Action(() => { status.Content = e.ToString(); }));
sta         


        
5条回答
  •  暖寄归人
    2020-12-20 07:32

    This will help you.

    To Execute synchronously:

    Application.Current.Dispatcher.Invoke(new Action(() => { status.Content = e.ToString(); }))
    

    To Execute Asynchronously:

    Application.Current.Dispatcher.BeginInvoke(new Action(() => { status.Content = e.ToString(); }))
    

提交回复
热议问题