rehansaeed.github.io
rehansaeed.github.io copied to clipboard
[Comment] Reactive Extensions (Rx) - Part 5 - Awaiting Observables
https://rehansaeed.com/reactive-extensions-part5-awaiting-observables/
David Christensen commented on 2017-01-11 12:04:21
In your observable ShowWindow example, I believe there is a (potential) race condition. Shouldn't your code be as shown below? Obviously for this particular example there is unlikely to be a problem, if you are demonstrating a pattern it might be worth correcting it?
public async Task ShowDialog()
{
Window window = new MyDialogWindow();
var closing= Observable
.FromEventPattern(
h => window.Closed += h,
h => window.Closed -= h);
window.Show();
await closing
.FirstAsync();
return window.DialogResult;
}
Muhammad Rehan Saeed commented on 2017-01-11 14:25:38
In your observable ShowWindow example, I believe there is a (potential) race condition. Shouldn't your code be as shown below? Obviously for this particular example there is unlikely to be a problem, if you are demonstrating a pattern it might be worth correcting it?
public async Task ShowDialog() { Window window = new MyDialogWindow(); var closing= Observable .FromEventPattern( h => window.Closed += h, h => window.Closed -= h); window.Show(); await closing .FirstAsync(); return window.DialogResult; }
Corrected, thanks!