none
How can I use await ?

    Question

  • Hi,

    I am having problems with using await.
    I  have 2 SQLite tables categoryWords and wordG.
    getTextWords(selectedItem) is intreupted it jumps to loadTBs

      public MainPage()
            {
                this.InitializeComponent();
                System.Diagnostics.Debug.WriteLine("In MainPage");
                roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

               System.Diagnostics.Debug.WriteLine("In MainPage Begin");

                if (roamingSettings.Values.ContainsKey("MyValueSelectedIndexCategory"))
                {
                    System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueSelectedIndexCategory].ToString():" + roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());
                    System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueCategory].ToString():" + roamingSettings.Values["MyValueCategory"].ToString());

                    comboBoxCategories.SelectedIndex = System.Convert.ToInt32(roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());
                    selectedItem = this.comboBoxCategories.SelectedItem.ToString();
                    getTextWords(selectedItem);
                  
                    loadTBs();

                   newGameFirstS(comboBoxCategories.SelectedItem.ToString());
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueSelectedIndexCategory].ToString(): 0");

                    comboBoxCategories.SelectedIndex = 0;
                    selectedItem = this.comboBoxCategories.SelectedItem.ToString();
                  
                    getTextWords(selectedItem);            
                  
                    loadTBs();

                    newGameFirstS(listCategories[0].ToString().Trim());
                }
    }

        private async void getTextWords(string selectedItem101)
            {
                System.Diagnostics.Debug.WriteLine("In getTextWords selectedItem101:" + selectedItem101);
              
                wordsGSViewModel2 = new wordsGSViewModel();

                wordsGS2 = new ObservableCollection<wordsGViewModel>();

               wordsGS2 = await wordsGSViewModel2.GetwordsGScategoryS(selectedItem101);
              //  wordsGS2 =  wordsGSViewModel2.GetwordsGScategory(selectedItem101);

                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2.Count().ToString{}:" + wordsGS2.Count().ToString());

                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord1:" + wordsGS2[0].nameWord1.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord2:" + wordsGS2[0].nameWord2.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord3:" + wordsGS2[0].nameWord3.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord4:" + wordsGS2[0].nameWord4.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord5:" + wordsGS2[0].nameWord5.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord7:" + wordsGS2[0].nameWord7.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord8:" + wordsGS2[0].nameWord8.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord9:" + wordsGS2[0].nameWord9.ToString());
                System.Diagnostics.Debug.WriteLine("In getTextWords wordsGS2[0].nameWord10:" + wordsGS2[0].nameWord10.ToString());
            
                words[0] = wordsGS2[0].nameWord1;
                words[1] = wordsGS2[0].nameWord2;
                words[2] = wordsGS2[0].nameWord3;
                words[3] = wordsGS2[0].nameWord4;
                words[4] = wordsGS2[0].nameWord5;
                words[5] = wordsGS2[0].nameWord6;
                words[6] = wordsGS2[0].nameWord7;
                words[7] = wordsGS2[0].nameWord8;
                words[8] = wordsGS2[0].nameWord9;
                words[9] = wordsGS2[0].nameWord10;

                txtWord1.Text = words[0].ToString();
                txtWord2.Text = words[1].ToString();
                txtWord3.Text = words[2].ToString();
                txtWord4.Text = words[3].ToString();
                txtWord5.Text = words[4].ToString();
                txtWord6.Text = words[5].ToString();
                txtWord7.Text = words[6].ToString();
                txtWord8.Text = words[7].ToString();
                txtWord9.Text = words[8].ToString();
                txtWord10.Text = words[9].ToString();

                wordTBs1 = new WordTBs();
                wordTBs2 = new WordTBs();
                wordTBs3 = new WordTBs();
                wordTBs4 = new WordTBs();
                wordTBs5 = new WordTBs();
                wordTBs6 = new WordTBs();
                wordTBs7 = new WordTBs();
                wordTBs8 = new WordTBs();
                wordTBs9 = new WordTBs();
                wordTBs10 = new WordTBs();         
        }
          private void loadTBs()
            {
                System.Diagnostics.Debug.WriteLine("In loadTBs: ");

                for (int i = 0; i < _maxRow; i++)
                {
                    for (int j = 0; j < _maxCol; j++)
                    {
                        TextBlock lbl = new TextBlock();
                        var tblock = lbl;
                        tblock.Name = "tb_" + i.ToString() + j.ToString();
                        tblock.Width = 50;
                        tblock.Height = 50; 
                        tblock.VerticalAlignment = VerticalAlignment.Center;
                        tblock.VerticalAlignment = VerticalAlignment.Bottom;
                        tblock.TextWrapping = TextWrapping.Wrap;
                        tblock.Margin = new Windows.UI.Xaml.Thickness(0, -12, 0, -12);
                        tblock.TextAlignment = TextAlignment.Center;
                        tblock.HorizontalAlignment = HorizontalAlignment.Center;
                        tblock.FontSize = 24;
                        tblock.FontStyle = Windows.UI.Text.FontStyle.Normal;
                        tblock.FontWeight = Windows.UI.Text.FontWeights.Bold;
                        tblock.Foreground = _blackBrush;
                        tblock.TextWrapping = TextWrapping.Wrap;
                        tblock.IsTapEnabled = true;

                        Grid.SetRow(tblock, i);
                        Grid.SetColumn(tblock, j);

                        tblock.Tapped += new TappedEventHandler(tblock_Tapped);
                     
                        GridX.Children.Add(tblock);
                    }
                }
            }

          public async Task<ObservableCollection<wordsGViewModel>> GetwordsGScategoryS(string category1)
           {
             //  System.Diagnostics.Debug.WriteLine("In Task GetwordsGScategoryS category1: " + category1);
                      
               wordsGS = new ObservableCollection<wordsGViewModel>();
               var db = new SQLite.SQLiteAsyncConnection(App.DBPath);
               var _wordsGS = await db.Table<wordsG>().Where(
                     p1 => p1.nameCategory == category1).OrderBy(
                     p2 => p2.nameCategory).ToListAsync().ConfigureAwait(false);
               foreach (var _wordsG in _wordsGS)
               {
                   var wordsG = new wordsGViewModel()
                   {
                       _id = _wordsG._id,
                       nameCategory = _wordsG.nameCategory,
                       nameWord1 = _wordsG.nameWord1,
                       nameWord2 = _wordsG.nameWord2,
                       nameWord3 = _wordsG.nameWord3,
                       nameWord4 = _wordsG.nameWord4,
                       nameWord5 = _wordsG.nameWord5,
                       nameWord6 = _wordsG.nameWord6,
                       nameWord7 = _wordsG.nameWord7,
                       nameWord8 = _wordsG.nameWord8,
                       nameWord9 = _wordsG.nameWord9,
                       nameWord10 = _wordsG.nameWord10
                   };
                   wordsGS.Add(wordsG);
               }
               return wordsGS;
           }

    The output

    In MainPage
    'Words Gen.exe' (CLR v4.0.30319: Immersive Application Domain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll'. Cannot find or open the PDB file.
    In MainPage Begin
    roamingSettings.Values[MyValueSelectedIndexCategory].ToString():3
    roamingSettings.Values[MyValueCategory].ToString():Presidents
    In getTextWords selectedItem101:Presidents

    ???????? It suppose to continue with

    In getTextWords wordsGS2.Count().ToString():1
    In getTextWords wordsGS2[0].nameWord1:ADAMS
    In getTextWords wordsGS2[0].nameWord2:BUCHANAN
    In getTextWords wordsGS2[0].nameWord3:CARTER
    In getTextWords wordsGS2[0].nameWord4:CLEVELAND
    In getTextWords wordsGS2[0].nameWord5:EISENHOWER
    In getTextWords wordsGS2[0].nameWord7:FORD
    In getTextWords wordsGS2[0].nameWord8:JOHNSON
    In getTextWords wordsGS2[0].nameWord9:LINCOLN
    In getTextWords wordsGS2[0].nameWord10:ROOSEVELT


    'Words Gen.exe' (CLR v4.0.30319: Immersive Application Domain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.WindowsRuntime.UI.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.WindowsRuntime.UI.Xaml.dll'. Cannot find or open the PDB file.
    In loadTBs:
    In PlaceWords: Presidents
    In PlaceWords  words[0]:
    In PlaceWords  words[1]:
    In PlaceWords  words[2]:
    In PlaceWords  words[3]:
    In PlaceWords  words[4]:
    In PlaceWords  words[5]:
    In PlaceWords  words[6]:
    In PlaceWords  words[7]:
    In PlaceWords  words[8]:
    In PlaceWords  words[9]:
    words.Count().ToString(): 10

    A first chance exception of type 'System.NullReferenceException' occurred in Words Gen.exe

    ????? Is null because getTextWords was not finished. And it's back.

    In getTextWords wordsGS2.Count().ToString():1
    In getTextWords wordsGS2[0].nameWord1:ADAMS
    In getTextWords wordsGS2[0].nameWord2:BUCHANAN
    In getTextWords wordsGS2[0].nameWord3:CARTER
    In getTextWords wordsGS2[0].nameWord4:CLEVELAND
    In getTextWords wordsGS2[0].nameWord5:EISENHOWER
    In getTextWords wordsGS2[0].nameWord7:FORD
    In getTextWords wordsGS2[0].nameWord8:JOHNSON
    In getTextWords wordsGS2[0].nameWord9:LINCOLN
    In getTextWords wordsGS2[0].nameWord10:ROOSEVELT


    ADRIAN DIBU

    Wednesday, August 27, 2014 2:38 PM

Answers

All replies

  • You will never be able to await in a constructor as object creation is a synchronous activity. In case if you have some initialization to do then make an asynchronous function out of it and then call that in constructor. The new function can internally await for multiple asynchronous functions and hence give you desired results by synchronizing those using await.

    Here is what you need to do

    private Task<bool> initDataTask;
    public MainPage()
    {
        this.InitializeComponent();
    
        initDataTask = initDataAsync();
    }
    
    
    private async Task<bool> initDataAsync()
    {
        System.Diagnostics.Debug.WriteLine("In MainPage");
        roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
    
        System.Diagnostics.Debug.WriteLine("In MainPage Begin");
    
        if (roamingSettings.Values.ContainsKey("MyValueSelectedIndexCategory"))
        {
            System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueSelectedIndexCategory].ToString():" + roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());
            System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueCategory].ToString():" + roamingSettings.Values["MyValueCategory"].ToString());
    
            comboBoxCategories.SelectedIndex = System.Convert.ToInt32(roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());
            selectedItem = this.comboBoxCategories.SelectedItem.ToString();
            await getTextWords(selectedItem);
    
            loadTBs();
    
            newGameFirstS(comboBoxCategories.SelectedItem.ToString());
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueSelectedIndexCategory].ToString(): 0");
    
            comboBoxCategories.SelectedIndex = 0;
            selectedItem = this.comboBoxCategories.SelectedItem.ToString();
    
            await getTextWords(selectedItem);
    
            loadTBs();
    
            newGameFirstS(listCategories[0].ToString().Trim());
        }
    
    
        return true;
    }

    If you still face issue, then post your full code on OneDrive and leave a link here. There were too-many unknowns in your code.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Thursday, August 28, 2014 4:07 AM
  • Hi adibu,

    Just want to share some info here, to understand the order better, you can also refer to this MSDN blog:

    http://msdn.microsoft.com/en-us/library/hh191443.aspx#BKMK_WhatHappensUnderstandinganAsyncMethod

       A good diagram for you to know when it may back.

    Best Regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, August 28, 2014 6:16 AM
  • Hi,

    Thanks for the prompt answers

    Vishal Kaushik at line

     await getTextWords(selectedItem);

    I had the error Canot await void.

    Thanks


    ADRIAN DIBU

    Thursday, August 28, 2014 12:43 PM
  • Hi,

    You can find the project at
    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3744&authkey=!AEZwdAY_GCiFH7s&ithint=file%2czip

    When I change categories I have sometime especialy when I select
    Presidents

    ContextSwitchDeadlock occurred
    Message: Managed Debugging Assistant 'ContextSwitchDeadlock' has detected a problem in 'C:\Users\ADRIAN\Documents\Visual Studio 2013\Projects\Words Gen\Words Gen\bin\x86\Debug\AppX\Words Gen.exe'.
    Additional information: The CLR has been unable to transition from COM context 0x15499b0 to COM context 0x1549a68 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
    Thanks


    ADRIAN DIBU

    Thursday, August 28, 2014 2:05 PM
  • Hi Adrian,

    I suggest you watch Easy Asynchrony with C#: No More Callbacks! This will help you develop your concepts for asynchronous programming using async-await.

    For immediate help you can change signature of "private async void getTextWords(string selectedItem101)" to "private async Task getTextWords(string selectedItem101)".

    Your app looks good and has lot of code to understand! In code your getTextWords is not async anymore. So it will really be time-consuming for me to understand it completely. So I think if you watch Video you will be able to help yourself.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Thursday, August 28, 2014 3:51 PM
  • Hi,
    Thanks for answer.
    I did what you suggested now when I select a category
    somtime works. It stucks when I select Preidents.

    Can be related to the fact in table wordsG _id 4 was deleted?

    _id   nameCategory

    1     Animals
    2     Fruits
    3     Presidents
    5     Flowers

    Selcting
    Animals - Fruits      OK
    Fruits  - Flowers     0K
    Flower  - Presidents  OK
    Presidents - Animals  OK
    Animals  - Presidents stucked

    private async Task getTextWords(string selectedItem101)
            {
               wordsGSViewModel2 = new wordsGSViewModel();

               wordsGS2 = new ObservableCollection<wordsGViewModel>();

               wordsGS2 = await wordsGSViewModel2.GetwordsGScategoryS(selectedItem101);
             
                words[0] = wordsGS2[0].nameWord1;
                words[1] = wordsGS2[0].nameWord2;
                words[2] = wordsGS2[0].nameWord3;
                words[3] = wordsGS2[0].nameWord4;
                words[4] = wordsGS2[0].nameWord5;
                words[5] = wordsGS2[0].nameWord6;
                words[6] = wordsGS2[0].nameWord7;
                words[7] = wordsGS2[0].nameWord8;
                words[8] = wordsGS2[0].nameWord9;
                words[9] = wordsGS2[0].nameWord10;

                txtWord1.Text = words[0].ToString();
                txtWord2.Text = words[1].ToString();
                txtWord3.Text = words[2].ToString();
                txtWord4.Text = words[3].ToString();
                txtWord5.Text = words[4].ToString();
                txtWord6.Text = words[5].ToString();
                txtWord7.Text = words[6].ToString();
                txtWord8.Text = words[7].ToString();
                txtWord9.Text = words[8].ToString();
                txtWord10.Text = words[9].ToString();

                wordTBs1 = new WordTBs();
                wordTBs2 = new WordTBs();
                wordTBs3 = new WordTBs();

                wordTBs4 = new WordTBs();
                wordTBs5 = new WordTBs();
                wordTBs6 = new WordTBs();
                wordTBs7 = new WordTBs();
                wordTBs8 = new WordTBs();
                wordTBs9 = new WordTBs();
                wordTBs10 = new WordTBs();
        }


     private async void ComboBoxCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (comboBoxCategories.SelectedIndex == -1)//check if anything is selected
                    return; //do nothing if nothing is selected

                if (e.RemovedItems != null && e.RemovedItems.Count > 0)
                {
                    if (this.comboBoxCategories.SelectedItem != null)
                    {
                        if (GridX.Children.Count() > 0)
                        {
                            removeChildren1();
                        }
                        resetTB();

                        selectedItem = this.comboBoxCategories.SelectedItem.ToString();

                        selectedCategory = listCategories.IndexOf(selectedItem);
                        comboBoxCategories.SelectedIndex = selectedCategory;

                        roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                        roamingSettings.Values["MyValueSelectedIndexCategory"] = selectedCategory.ToString();
                        roamingSettings.Values["MyValueCategory"] = selectedItem.ToString();
                       
                        await getTextWords(selectedItem);
                    
                        loadTBs();

                        newGameFirstS(comboBoxCategories.SelectedItem.ToString());
                    }
                }

            }

    and in ViewModel

       public async Task<ObservableCollection<wordsGViewModel>> GetwordsGScategoryS(string category1)
           {
               wordsGS = new ObservableCollection<wordsGViewModel>();
               var db = new SQLite.SQLiteAsyncConnection(App.DBPath);

                 var _wordsGS = await db.Table<wordsG>().Where(
                     p1 => p1.nameCategory == category1).OrderBy(
                     p2 => p2.nameCategory).ToListAsync().ConfigureAwait(false);

               foreach (var _wordsG in _wordsGS)
               {
                   var wordsG = new wordsGViewModel()
                   {
                       _id = _wordsG._id,
                       nameCategory = _wordsG.nameCategory,
                       nameWord1 = _wordsG.nameWord1,
                       nameWord2 = _wordsG.nameWord2,
                       nameWord3 = _wordsG.nameWord3,
                       nameWord4 = _wordsG.nameWord4,
                       nameWord5 = _wordsG.nameWord5,
                       nameWord6 = _wordsG.nameWord6,
                       nameWord7 = _wordsG.nameWord7,
                       nameWord8 = _wordsG.nameWord8,
                       nameWord9 = _wordsG.nameWord9,
                       nameWord10 = _wordsG.nameWord10
                   };
                   wordsGS.Add(wordsG);
               }
               return wordsGS;
           }


    ADRIAN DIBU

    Thursday, August 28, 2014 9:04 PM
  • Hi,

    Please can somebody to explain the error

    ContextSwitchDeadlock occurred.

    It means the table is accessed while is in used, and how can I prevented.

    Best regards


    ADRIAN DIBU

    Friday, August 29, 2014 2:34 PM
  • Hi,

    The new link is

    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3757&authkey=!ABYS2YtERDTCBgY&ithint=file%2czip

    I made a lot of changes.

    I tried to use where is possible async.

    I still have ContextSwitchDeadlock occurred.

    Thanks


    ADRIAN DIBU

    Friday, August 29, 2014 2:59 PM
  • Hi,

    New link

    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3758&authkey=!ALtsH2U-kzzz2VQ&ithint=file%2czip

    Still having ContextSwitchDeadlock occurred sometime and I can't figure why.

    Please take a look at

    private async void ComboBoxCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("In ComboBoxCategories");

                System.Diagnostics.Debug.WriteLine("In ComboBox selectedIndex at begining: " + this.comboBoxCategories.SelectedIndex.ToString());
                System.Diagnostics.Debug.WriteLine("In ComboBox selectedItem at begining: " + this.comboBoxCategories.SelectedItem.ToString());

                if (comboBoxCategories.SelectedIndex == -1)//check if anything is selected
                    return; //do nothing if nothing is selected

               await getTextWords(roamingSettings.Values["MyValueCategory"].ToString());


               if (GridX.Children.Count() > 0)
               {
                   removeChildren1();
               }
               System.Diagnostics.Debug.WriteLine("In ComboBox after GridX.Children.Count.ToString(): " + GridX.Children.Count.ToString());

               resetTB();
               //  resetWordTBs();
               loadTBs();

               System.Diagnostics.Debug.WriteLine("In ComboBox after loadTBs GridX.Children.Count.ToString(): " + GridX.Children.Count.ToString());    
            
               roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

               roamingSettings.Values["MyValueSelectedIndexCategory"] = this.comboBoxCategories.SelectedIndex.ToString(); // selectedCategory.ToString();
               roamingSettings.Values["MyValueCategory"] = this.comboBoxCategories.SelectedItem.ToString(); //selectedItem.ToString();
      
               await newGameFirstS(roamingSettings.Values["MyValueCategory"].ToString());
      }

     protected async override void OnNavigatedTo(NavigationEventArgs e)
            {
                navigationHelper.OnNavigatedTo(e);
                System.Diagnostics.Debug.WriteLine("In OnNavigatedTo");

               roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

               System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueSelectedIndexCategory].ToString():" + roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());
               System.Diagnostics.Debug.WriteLine("roamingSettings.Values[MyValueCategory].ToString():" + roamingSettings.Values["MyValueCategory"].ToString());

                await getCategories();
                comboBoxCategories.SelectedIndex = System.Convert.ToInt32(roamingSettings.Values["MyValueSelectedIndexCategory"].ToString());

                loadTBs();

                await getTextWords(roamingSettings.Values["MyValueCategory"].ToString());

                if (GridX.Children.Count() > 0)
                {
                    removeChildren1();
                }
                System.Diagnostics.Debug.WriteLine("In ComboBox after GridX.Children.Count.ToString(): " + GridX.Children.Count.ToString());

                resetTB();
                //  resetWordTBs();
                loadTBs();
                await newGameFirstS(roamingSettings.Values["MyValueCategory"].ToString());
     
        } 

    Thanks


    ADRIAN DIBU

    Sunday, August 31, 2014 12:58 AM
  • Hi.

    New link

    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3759&authkey=!AHUcjCMfhVxAXSQ&ithint=file%2czip

    What I suppose to consider the fact
    System are calling:
    ComboBoxCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
    not only when I change Categories
     private async void ComboBoxCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("In ComboBoxCategories");

                System.Diagnostics.Debug.WriteLine("In ComboBox selectedIndex at begining: " + this.comboBoxCategories.SelectedIndex.ToString());
                System.Diagnostics.Debug.WriteLine("In ComboBox selectedItem at begining: " + this.comboBoxCategories.SelectedItem.ToString());

                if (comboBoxCategories.SelectedIndex == -1)//check if anything is selected
                    return; //do nothing if nothing is selected

                roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                if (comboBoxCategories.SelectedItem.ToString().Equals(roamingSettings.Values["MyValueCategory"].ToString()))
                {
                    // Do nothiing already loaded
                     System.Diagnostics.Debug.WriteLine("In ComboBox Do nothing");
              
                }
                else
                {
                System.Diagnostics.Debug.WriteLine("In ComboBox selection changed");

               if (GridX.Children.Count() > 0)
               {
                   removeChildren1();
               }
               System.Diagnostics.Debug.WriteLine("In ComboBox after GridX.Children.Count.ToString(): " + GridX.Children.Count.ToString());

               resetTB();
               //  resetWordTBs();
               loadTBs();

               System.Diagnostics.Debug.WriteLine("In ComboBox after loadTBs GridX.Children.Count.ToString(): " + GridX.Children.Count.ToString());       
           
               roamingSettings.Values["MyValueSelectedIndexCategory"] = this.comboBoxCategories.SelectedIndex.ToString(); // selectedCategory.ToString();
               roamingSettings.Values["MyValueCategory"] = this.comboBoxCategories.SelectedItem.ToString(); //selectedItem.ToString();

               await getTextWords(roamingSettings.Values["MyValueCategory"].ToString());
               await newGameFirstS(roamingSettings.Values["MyValueCategory"].ToString());

                }
                System.Diagnostics.Debug.WriteLine("In ComboBox selectedIndex at the end: " + this.comboBoxCategories.SelectedIndex.ToString());
                System.Diagnostics.Debug.WriteLine("In ComboBox selectedItem at the end: " + this.comboBoxCategories.SelectedItem.ToString());
    }
    See the output:

    In Init MainPage App.mainPageFirstLoad == true
    In Init MainPage  finished
    In MainPage App.passedVal.ToString(): 0(0)Gray[2]1,0;0H0Z
    App.passedVal0(0)Gray[2]1,0;0H0Z
    In navigationHelper_LoadState no key  MyValueTimeStopS
    In navigationHelper_LoadState no key  MyValueScoreS
    In navigationHelper_LoadState
    In OnNavigatedTo
    roamingSettings.Values[MyValueSelectedIndexCategory].ToString():2
    roamingSettings.Values[MyValueCategory].ToString():Fruits
    In Page_Load
    In ComboBoxCategories !!!!!
    In ComboBox selectedIndex at begining: 2
    In ComboBox selectedItem at begining: Fruits
    In ComboBox Do nothing
    In ComboBox selectedIndex at the end: 2
    In ComboBox selectedItem at the end: Fruit
    In loadTBs:
    In getTextWords selectedItem101:Fruits
    In getTextWords wordsGS2.Count().ToString{}:1
    In getTextWords wordsGS2[0].nameWord1:APPLE
    In getTextWords wordsGS2[0].nameWord2:APRICOT
    In getTextWords wordsGS2[0].nameWord3:BANANA
    In getTextWords wordsGS2[0].nameWord4:CHERRY
    In getTextWords wordsGS2[0].nameWord5:FIG
    In getTextWords wordsGS2[0].nameWord7:GUAVA
    In getTextWords wordsGS2[0].nameWord8:MANGO
    In getTextWords wordsGS2[0].nameWord9:PEACH
    In getTextWords wordsGS2[0].nameWord10:PEAR
    In removeChildren1 after GridX.Children.Count.ToString(): 0
    In ComboBox after GridX.Children.Count.ToString(): 0
    In resetTB
    In loadTBs:
    In newGameFirstS selectedItem: Fruits
    In PlaceWords: Fruits
    In PlaceWords  words[0]: APPLE
    In PlaceWords  words[1]: APRICOT
    In PlaceWords  words[2]: BANANA
    In PlaceWords  words[3]: CHERRY
    In PlaceWords  words[4]: FIG
    In PlaceWords  words[5]: GRAPE
    In PlaceWords  words[6]: GUAVA
    In PlaceWords  words[7]: MANGO
    In PlaceWords  words[8]: PEACH
    In PlaceWords  words[9]: PEAR
    In PlaceWords  words.Count().ToString(: 10
    wordTBs1.FirstTB: tb_65
    wordTBs2.FirstTB: tb_33
    wordTBs3.FirstTB: tb_67
    wordTBs4.FirstTB: tb_71
    wordTBs5.FirstTB: tb_83
    wordTBs6.FirstTB: tb_09
    wordTBs7.FirstTB: tb_16
    wordTBs8.FirstTB: tb_92
    wordTBs9.FirstTB: tb_20
    wordTBs10.FirstTB: tb_68
    In FillTheRest()
    In writeInTBs
    In ComboBoxCategories
    In ComboBox selectedIndex at begining: 1
    In ComboBox selectedItem at begining: Flowers
    In ComboBox selection changed
    In removeChildren1 after GridX.Children.Count.ToString(): 0
    In ComboBox after GridX.Children.Count.ToString(): 0
    In resetTB
    In loadTBs:
    In ComboBox after loadTBs GridX.Children.Count.ToString(): 100
    In getTextWords selectedItem101:Flowers
    In getTextWords wordsGS2.Count().ToString{}:1
    In getTextWords wordsGS2[0].nameWord1:AMERYLLIS
    In getTextWords wordsGS2[0].nameWord2:ANEMONE
    In getTextWords wordsGS2[0].nameWord3:ASTER
    In getTextWords wordsGS2[0].nameWord4:CALLA
    In getTextWords wordsGS2[0].nameWord5:CARNATION
    In getTextWords wordsGS2[0].nameWord7:DAHLIA
    In getTextWords wordsGS2[0].nameWord8:FREESIA
    In getTextWords wordsGS2[0].nameWord9:GARDENIA
    In getTextWords wordsGS2[0].nameWord10:ROSE
    In newGameFirstS selectedItem: Flowers
    In PlaceWords: Flowers
    In PlaceWords  words[0]: AMERYLLIS
    In PlaceWords  words[1]: ANEMONE
    In PlaceWords  words[2]: ASTER
    In PlaceWords  words[3]: CALLA
    In PlaceWords  words[4]: CARNATION
    In PlaceWords  words[5]: DAFFODIL
    In PlaceWords  words[6]: DAHLIA
    In PlaceWords  words[7]: FREESIA
    In PlaceWords  words[8]: GARDENIA
    In PlaceWords  words[9]: ROSE
    In PlaceWords  words.Count().ToString(: 10
    wordTBs1.FirstTB: tb_69
    wordTBs2.FirstTB: tb_33
    wordTBs3.FirstTB: tb_74
    wordTBs4.FirstTB: tb_57
    wordTBs5.FirstTB: tb_11
    wordTBs6.FirstTB: tb_80
    wordTBs7.FirstTB: tb_48
    wordTBs8.FirstTB: tb_88
    wordTBs9.FirstTB: tb_98
    wordTBs10.FirstTB: tb_24
    In FillTheRest()
    In writeInTBs
    In ComboBox selectedIndex at the end: 1
    In ComboBox selectedItem at the end: Flowers
    In Init dispatcherTimer_Tick Navigate


    ADRIAN DIBU

    Sunday, August 31, 2014 5:20 PM
  • Hi,
    The new link
    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3760&authkey=!ACZc6sJwX8tuDAM&ithint=file%2czip

    Output after changing Categories.
    When I selected Presidents
    It stacks and no
    wordTBs10.FirstTB ??????????/
    In ComboBoxCategories
    In ComboBox selectedIndex at begining: 1
    In ComboBox selectedItem at begining: Flowers
    In ComboBox selection changed
    In getTextWords selectedItem101:Flowers
    In wordsGS2.Count().ToString{}:1
    In getTextWords wordsGS2[0].nameWord1:AMERYLLIS
    In getTextWords wordsGS2[0].nameWord2:ANEMONE
    In getTextWords wordsGS2[0].nameWord3:ASTER
    In getTextWords wordsGS2[0].nameWord4:CALLA
    In getTextWords wordsGS2[0].nameWord5:CARNATION
    In getTextWords wordsGS2[0].nameWord7:DAHLIA
    In getTextWords wordsGS2[0].nameWord8:FREESIA
    In getTextWords wordsGS2[0].nameWord9:GARDENIA
    In getTextWords wordsGS2[0].nameWord10:ROSE
    In removeChildren1 after GridX.Children.Count.ToString(): 0
    In resetTB
    In loadTBs:
    wordTBs1.FirstTB: tb_92
    wordTBs2.FirstTB: tb_70
    wordTBs3.FirstTB: tb_05
    wordTBs4.FirstTB: tb_03
    wordTBs5.FirstTB: tb_19
    wordTBs6.FirstTB: tb_93
    wordTBs7.FirstTB: tb_84
    wordTBs8.FirstTB: tb_21
    wordTBs9.FirstTB: tb_88
    wordTBs10.FirstTB: tb_97
    In FillTheRest()
    In writeInTBs
    In ComboBox selectedIndex at the end: 1
    In ComboBox selectedItem at the end: Flowers
    In ComboBoxCategories
    In ComboBox selectedIndex at begining: 2
    In ComboBox selectedItem at begining: Fruits
    In ComboBox selection changed
    In getTextWords selectedItem101:Fruits
    In wordsGS2.Count().ToString{}:1
    In getTextWords wordsGS2[0].nameWord1:APPLE
    In getTextWords wordsGS2[0].nameWord2:APRICOT
    In getTextWords wordsGS2[0].nameWord3:BANANA
    In getTextWords wordsGS2[0].nameWord4:CHERRY
    In getTextWords wordsGS2[0].nameWord5:FIG
    In getTextWords wordsGS2[0].nameWord7:GUAVA
    In getTextWords wordsGS2[0].nameWord8:MANGO
    In getTextWords wordsGS2[0].nameWord9:PEACH
    In getTextWords wordsGS2[0].nameWord10:PEAR
    In removeChildren1 after GridX.Children.Count.ToString(): 0
    In resetTB
    In loadTBs:
    wordTBs1.FirstTB: tb_58
    wordTBs2.FirstTB: tb_40
    wordTBs3.FirstTB: tb_69
    wordTBs4.FirstTB: tb_72
    wordTBs5.FirstTB: tb_71
    wordTBs6.FirstTB: tb_17
    wordTBs7.FirstTB: tb_25
    wordTBs8.FirstTB: tb_09
    wordTBs9.FirstTB: tb_95
    wordTBs10.FirstTB: tb_00
    In FillTheRest()
    In writeInTBs
    In ComboBox selectedIndex at the end: 2
    In ComboBox selectedItem at the end: Fruits
    In ComboBoxCategories
    In ComboBox selectedIndex at begining: 3
    In ComboBox selectedItem at begining: Presidents
    In ComboBox selection changed
    In getTextWords selectedItem101:Presidents
    In wordsGS2.Count().ToString{}:1
    In getTextWords wordsGS2[0].nameWord1:ADAMS
    In getTextWords wordsGS2[0].nameWord2:BUCHANAN
    In getTextWords wordsGS2[0].nameWord3:CARTER
    In getTextWords wordsGS2[0].nameWord4:CLEVELAND
    In getTextWords wordsGS2[0].nameWord5:EISENHOWER
    In getTextWords wordsGS2[0].nameWord7:FORD
    In getTextWords wordsGS2[0].nameWord8:JOHNSON
    In getTextWords wordsGS2[0].nameWord9:LINCOLN
    In getTextWords wordsGS2[0].nameWord10:ROOSEVELT
    In removeChildren1 after GridX.Children.Count.ToString(): 0
    In resetTB
    In loadTBs:
    wordTBs1.FirstTB: tb_85
    wordTBs2.FirstTB: tb_01
    wordTBs3.FirstTB: tb_48
    wordTBs4.FirstTB: tb_91
    wordTBs5.FirstTB: tb_00
    wordTBs6.FirstTB: tb_02
    wordTBs7.FirstTB: tb_69
    wordTBs8.FirstTB: tb_29
    wordTBs9.FirstTB: tb_81

    ??????????????

    ADRIAN DIBU

    Monday, September 01, 2014 2:42 PM
  • Hi,

    In fact if I wait a few seconds between categories

    change app works.

    It appear I start a new dataaccess while the

    preview wasn't finish and I have deadlock.

    If so how can I prevented?

    Thanks


    ADRIAN DIBU

    Monday, September 01, 2014 4:13 PM
  • Hi,

    From 534 viewers nobody with any idea?

    Please tell me your opinion, I am out of ideas.

    Thanks


    ADRIAN DIBU

    Monday, September 01, 2014 11:18 PM
  • Hi,

    I am still waiting, somebody why I have deadlock?

    Any idea is really appreciated.

    Thanks


    ADRIAN DIBU

    Thursday, September 04, 2014 12:45 AM
  • Hi,

    New link

    https://onedrive.live.com/redir?resid=857BC62170EDDB22!3773&authkey=!ALkCYpOo7VJFsM8&ithint=file%2czip

    It works if I don't change categories to fast.

    I don't know how long to delay between changes or to detect if database is accessed.

    Please help me.

    Thanks


    ADRIAN DIBU

    Thursday, September 04, 2014 1:32 PM
  • It works if I don't change categories to fast.

    I haven't read through your code :) but this problem is almost always caused by "async re-entrancy".

    I wrote a blog with advice on how to fix it:

    http://blogs.msdn.com/b/lucian/archive/2014/03/03/async-re-entrancy-and-the-patterns-to-deal-with-it.aspx

    • Marked as answer by adibu Monday, September 15, 2014 5:33 PM
    Monday, September 15, 2014 4:18 PM