brianchance / MvvmCross-UserInteraction

MvvmCross plugin for interacting with the user from a view model
MIT License
43 stars 44 forks source link

tcs.TrySetResult used instead of tcs.SetResult to avoid crash #21

Closed alexshikov closed 9 years ago

alexshikov commented 9 years ago

I'm receiving rare crash reports related tcs.SetResult. It looks like there are cases when user either typed twice on the button (due to some device lag or something) or because the system calls OnClick event twice.

In any case it's looks like a good solution to use tcs.TrySetResult instead of tcs.SetResult to avoid crashes.

System.InvalidOperationExceptionThe underlying Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled.

at System.Threading.Tasks.TaskCompletionSource`1[System.Boolean].SetResult (Boolean result)
at Chance.MvvmCross.Plugins.UserInteraction.Touch.UserInteraction+<Confirm>c__AnonStorey1+<Confirm>c__AnonStorey2.<>m__0 (System.Object sender, UIKit.UIButtonEventArgs args)
at UIKit.UIAlertView+_UIAlertViewDelegate.Clicked (UIKit.UIAlertView alertview, nint buttonIndex) 
...