icsharpcode / SharpDevelop

#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
2.08k stars 771 forks source link

Using Dispatcher when accessing the ItemsSource of the start page #759

Open mmgerald opened 8 years ago

mmgerald commented 8 years ago

When using SDA the initialization of recent projects on start page, because after await another thread tried to access ItemSource

mmgerald commented 8 years ago

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the #develop open source product (the "Contribution"). My Contribution is licensed under the MIT License.

mmgerald commented 8 years ago

Are there any news? Something missing? is it possible to merge the pull request?

mrward commented 8 years ago

If BuildRecentProjectList is called on the UI thread then setting the ItemsSource should be called on the UI thread so you should not need to use the dispatcher. The Task.Run part will be run on another background thread. This task is awaited and so the code adding items to the list's ItemSource should execute on the UI thread.

mmgerald commented 8 years ago

I agree that the code adding items to the list's ItemSource should execute on the UI thread. But the behavior is different when using SDA (Sharp Develop for Applications). After await, a MTA thread is returned form Thread Pool, that executes the code. In this case Sharp Develop is hosted in another process, therefore the Task Framework behave different.

It is reproducible when using samples\SdaUser, when including the StartPage Add-In.