title: Synchronize UI thread (Pivot item from active to non active view)
body: <p>I would like to synchronize the UI thread with changes in a view (pivot item 1 active view) which is active when the changes begin and switch to non active state (User interaction like changing the pivot item from the pivot item 1 to pivot item 2) before finishing the changes.</p>
  
  <p>The changes never happens and the view is restored as the point when switching from active to non active state.</p>
  
  <p>The UI stack composed from</p>
  
  <p>ScrollViewer</p>
  
  <ul>
  <li>Grid</li>
  <li>List view</li>
  <li>Grid</li>
  </ul>
  
  <p>The grid controls contains progress bars to handle refresh</p>
  
  <pre><code>    private async void scrollViewer_ViewChanged2(object sender, ScrollViewerViewChangedEventArgs e)
      {
          var listView = scrollViewer.GetDescendantsOfType&lt;ListView&gt;().FirstOrDefault();
          var context = DataContext as IMainStreamViewModel;
  
          if (e.IsIntermediate) return;
          var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
  
          if (Math.Abs(scrollViewer.VerticalOffset) &lt; 0.01 &amp;&amp; _isPullRefresh)
          {
              // Adding item the Observable collection that is the
              // the item source for the listview
              // The method just add element using the core dispatcher
              context.PullToRefreshInsertion_Top(dispatcher, listView);
          }
          else if (_scrollBar.Value &gt;= _scrollBar.Maximum)
          {
              // same action but in bottom of the observable collection
              // The method just add element using the core dispatcher
              context.PullToRefreshAdd_Bottom(dispatcher, listView);
          }
  
          _isPullRefresh = false;
          // Set the current element to be displayed in the list view
          await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
              () =&gt; listView.ScrollIntoView(listView.SelectedItem));
          // Scroll to the the listview and hidding the progress control
          await Task.FromResult(scrollViewer.ChangeView(null, 60, null));
  
      }
  </code></pre>
  
  <p>Finally the element may be added but the scroll viewer dont reset his position and listview also</p>
  
  <p>How to solve the sychronisation, i think the problem come from the IsActiveView state if the UI element is not in the ACTIVE VIEW it doesn't execute or skip the event.</p>
  
  <p><strong>UPDATE 1 :</strong></p>
  
  <p>The situation is as :</p>
  
  <p>Pivot control that contain two pivot items :</p>
  
  <ul>
  <li>Pivot item one contain :</li>
  <li>***Scrollviewer</li>
  <li>******Grid that contain a custom progress bar top refresh</li>
  <li>******ListView containing the data that user can see and interact with</li>
  <li>******Grid that contain a custom progress bar bottom refresh</li>
  <li>Pivot item two contain some Richtextblock ...</li>
  </ul>
  
  <p>When i'm doing the pull to refresh from the pivot item one and before the custom progress bar disappears do swipe to the next pivot item.</p>
  
  <p>When i come back to the first pivot item, it was freezed at the state when i want to refresh and the top or bottom progress bar still visible.</p>
  
  <p>I solved that by doing some trick and add some isVisible property in my view model and i fire the event whenever i'm in this pivot item i call updatelayout() and now it works.</p>
  
  <p>I think the problem come from the fact when i'm doing swipe, the UI thread cancels all operations and start executing the operations attached to the active view this is why the update layout event for the first pivot item never fire.</p>