How to make Dispatcher.BeginInvoke run in background in VB.net?

后端 未结 2 1328
误落风尘
误落风尘 2021-01-16 02:47

I need to run some part of application in background and allow user to update the UI while the sub is running in the background. I searched and I found out that in WPF I sho

相关标签:
2条回答
  • 2021-01-16 03:30

    The dispatcher should be used to update UI objects from a separate thread, it does not actually spawn up the thread for you. If you are using .NET 4.0 or higher, you can use the TPL library to spawn your thread, do your work, then update your UI object via the dispatcher from the background thread.

    Task.Factory.StartNew(Sub() DoBackgroundWork())

    Then, inside DoBackgroundWork whenever you want to update your UI...

    Dispatcher.BeginInvoke(Sub() txtBox1.Text = "End")

    0 讨论(0)
  • 2021-01-16 03:30

    you can call to the general application.

    Application.Current.Dispatcher.Invoke()
    
    0 讨论(0)
提交回复
热议问题