Created
June 25, 2013 17:47
-
-
Save mcintyre321/5860606 to your computer and use it in GitHub Desktop.
Flawed (?) sync methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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