Saturday, 15 March 2014

c# - Application Crashed while async task is override -


I am working on Windows Phone 8.1. There I am creating simple page, the first page is in two buttons.

& lt; Grid & gt; & Lt; StackPanel & gt; & Lt; Button x: name = "btnNextPage" content = "next page" horizontal alignment = "center" click = "btnxide page link" /> & Lt; Button x: name = "btnMessageDisplay" content = "display message" horizontal align = "center" = "btnMessageDisplay_Click" /> & Lt; / StackPanel & gt; & Lt; / Grid & gt;

Here the first button is moved from one page to the other and the other is shown as a simple message dialog box as follows.

  MessageDialog msg = New MessageDialog ("", ""); Async Private Zero btnMessageDisplay_Click (Object Sender, RoutedEventArgs E) {msg.Content = "Hello Friends ..."; Msg.Title = "Message"; Msg.ShowAsync (); } Private Zero btnNextPage_Click (Object Sender, RoutedEventArgs e) {frame. Navigate (typef (secondpages)); }  

This work is fine but the problem occurs when the first button is pressed and double click on the BTN Message Display button, the application is crashing.

I know why this happens due to the asynchronous work. But I do not know the solution to this problem. Please give me the solution.

I'm following the exception.

A type of 'System.UnauthorizedAccessException' occurred in asyncTesting.exe, but it was not operated in the user code

>

Access denied (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I can not get directions on MSDN, but system at WP at one time A dialogue can be shown when you try to show the second dialog, then the system will throw unauthorized exception .

Take a simple test:

  Private Zero TestBtn_Click (Object Sender, RoutedEventArgs e) {DispatcherTimer timer1 = New DispatcherTimer () {Interval = timespan; formsconds (3)}; Dispatcher timer timer 2 = new dispatch timer () {interval = timespace.frossaconds (4)}; Timer 1.Tick + = async (s1, e1) = & gt; {Timer1.Stop (); Wait for new mess-dialog ("first"). ShowAsync (); }; Timer 2.Tick + = async (s2, e2) => {Timer2.Stop (); Wait for new message-dialog ("seconds"). ShowAsync (); }; Timer1.Start (); Timer2.Start (); }  

If you close the dialog before quickly, it will be fine, but if you do not, then the second (when the second dialog will be shown), the exception .

The same situation is in your case - you click on the button responsible for displaying the dialog - the first one shows, but the second resolved clicked event throws an exception in this case, for example you Simple flags can be used:

  private bool btnResolved = true; Async Private Zero return btnMessageDisplay_Click (Object Sender, RoutedEventArgs e) {if (BtnResolved); BTrode = False; Msg.Content = "Hello Friends ..."; Msg.Title = "Message"; Msg.ShowAsync (); Btn resold = true; }  

You can think of the disable button instead of using a flag.


No comments:

Post a Comment