If you're going to be using multi-threading then you could do that in your ViewModel and use the SynchronizationContext class to ensure that the event is raised on the UI thread. ![]() ![]() At some point, you need to marshal a method call to the UI thread. The problem is that updating a property on a secondary thread is going to raise the corresponding event on that same secondary thread, so if you've bound a control then you're still trying to modify that control on that same secondary thread. Stop looking at the irrelevant differences and focus on the relevant similarities. A Task and a BackgroundWorker are simply two different mechanisms to execute code on a secondary thread but both end up using a thread pool thread so there's not even that difference. ![]() The principle is that if you are executing code on a secondary thread and you want to update the UI then you need to marshal a method call to the UI thread to do that. The use of the BackgroundWorker was simply convenient for the example but is irrelevant to the principle. It doesn t matter which secondary thread you use, a secondary thread is not the UI thread. ![]() As I said, any modification of a control must be done specifically on the UI thread. If you create a new Task then you're still executing it on a secondary thread. A Task is executed on a thread pool thread.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |