Skip to content

Instantly share code, notes, and snippets.

@mcintyre321
Created June 25, 2013 17:47
Show Gist options
  • Save mcintyre321/5860606 to your computer and use it in GitHub Desktop.
Save mcintyre321/5860606 to your computer and use it in GitHub Desktop.
Flawed (?) sync methods
void SyncToSignalR<T>(ObservableCollection<T> oc)
{
oc.OnCollectionChanged += (o, e) { Hub.Send(e.NewItems.Cast<T>()); }
//race condition, what if OnCollectionChanged fires before send is donev
Hub.Send(oc));
}
//alternatiive
void SyncToSignalR2<T>(ObservableCollection<T> oc)
{
Hub.Send(oc)); //sync current content of collection
//race condition, what if OnCollectionChanged fires before event handler is hooked up
oc.OnCollectionChanged += (o, e) { Hub.Send(e.NewItems.Cast<T>()); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment