c# - navigate after code on button click -


I'm wondering is performed on a bit and after some code a button of a shell that I another Click Navigate to the page? Here's what I have

  private void saveButton_Click (object sender, RoutedEventArgs e) {try {address = bitCoinAddress.Text; Create a MyIsolatedStorage.CreateDirectory ("Contact") called the // location directory; // (, FileMode.Create, myIsolatedStorage) New IsolatedStorageFileStream ( "Contact \\ me.txt") locationData create directories WriteFile = new StreamWriter called location.txt within the file; WriteFile.WriteLine (address); WriteFile.Close (); Navigation service Navigate (new Uri ("/ Contacts.xaml", Uricund.Relative)); } Hold (exception b) {message box. Show ("Error saving bittoon address"); Console.light line ("an error occurred:" + b); }   

Most certainly, the problem is in this line: < Pre> myIsolatedStorage.CreateDirectory ("Contact");

Because you can not guarantee button_click event that myIsolatedStorage object is still alive (it may already be settled, the code should be wrapped using the < / Em> to stop that). In this style you rewrite the code:

  using (myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication ()) {if (! MyIsolatedStorage.DirectoryExists ( "Contact")) myIsolatedStorage.CreateDirectory ( "Contact") ; Using (WriteFile = new StreamWriter (new IsolatedStorageFileStream ( "Contact \\ me.txt", FileMode.Create, myIsolatedStorage))) {writeFile.WriteLine (address); }} Navigation service Navigate (new Uri ("/ Contacts.xaml", Uricund.Relative));  

This code works fine for me Hope it helps.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -