title: Clock program employing ThreadPoolTimer C# uwp
body: <p>this is modelled on a answer to a previous question <a href="https://stackoverflow.com/questions/34570755/how-to-display-a-clock-with-the-current-time-in-a-windows-core-iot-app">How to display a clock with the current time in a Windows Core IoT app?</a>, I get an exception: "The application called an interface that was marshalled for a different thread." If I change the property with an click event, the binding works.</p>
  
  <pre><code>public class RunClock: INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged = delegate { };
      ThreadPoolTimer _clockTimer = null;
      private string clock="";
      public string Clock
      {
          set
          {
              clock= value;
              this.OnPropertyChanged();
          }
          get { return clock; } }
      public RunClock()
      {
  
          _clockTimer = ThreadPoolTimer.CreatePeriodicTimer(_clockTimer_Tick, TimeSpan.FromMilliseconds(1000));            
      private void _clockTimer_Tick(ThreadPoolTimer timer)
      {
          DateTime datetime = DateTime.Now;
          Str1 = datetime.ToString();
      }
      public void OnPropertyChanged([CallerMemberName] string propertyName = null)
      {
          this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>
  
  <p>and the Xaml:</p>
  
  <pre><code>&lt;TextBlock Margin="15" Name="timec" Text="{x:Bind Path=RunClock.Clock, Mode=OneWay}"&gt;&lt;/TextBlock&gt;
  </code></pre>
  
  <p>Thank you in advance!</p>
  
  <p>Update, working code: </p>
  
  <pre><code> public class test : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged = delegate { };
      ThreadPoolTimer _clockTimer = null;
      private string str1 = "";
      public string Str1
      {
          set
          {
              str1 = value;
              this.OnPropertyChanged();
          }
          get { return str1; }
      }
      public test()
      {
  
          _clockTimer = ThreadPoolTimer.CreatePeriodicTimer(_clockTimer_Tick, TimeSpan.FromMilliseconds(1000));
                  }
      async private void _clockTimer_Tick(ThreadPoolTimer timer)
      {
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =&gt;
          {
              DateTime dt = DateTime.Now;
              Str1 = dt.ToString();
          });
      }
      public void OnPropertyChanged([CallerMemberName] string propertyName = null)
      {
          this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>
  
  <p>Xaml (test1 is an instance of he viewmodel):</p>
  
  <pre><code>                &lt;TextBlock Margin="15" Name="timec" Text="{x:Bind test1.Str1, Mode=OneWay}"&gt;&lt;/TextBlock&gt;
  </code></pre>