For example, I\'ve got a business object Person
:
class Person : INotifyPropertyChanged
{
string Name { get; set; }
DateTime DateOfBirth { ge
This doesn't answer your question, but I try as far as possible to avoid this problem.
Because of the existence of data binding, I make sure the only code that can update business objects is code that's running on the GUI thread.
For async operations, I adopt a pattern of:
I can recommend the System.Threading.Tasks.Task class as an abstraction around most of the above steps. It's new in .NET 4.0, but it's also available as a separate download for .NET 3.5 apps.
Steps (1) and (2) are what the Task
class does without any customisation. You can achieve (3) by spawning a separate Task
from inside the background thread and specifying TaskScheduler.FromCurrentSynchronizationContext as a scheduler. (You'll need to call FromCurrentSynchronizationContext
from the GUI thread, in step (1), not from the background thread.)