title: Xamarin.Android how to auto update RecyclerView
body: <p>Following <a href="https://blog.xamarin.com/recyclerview-highly-optimized-collections-for-android-apps/" rel="nofollow noreferrer">this</a> article I created a simple application that displays a list. The list I get from a web service (.asmx web service).</p>
  <p>I want to auto update <code>RecyclerView</code> every 5 seconds and I have no idea how to do it.</p>
  <p>In WinForms I would have used the Timer component, but I don't know how this works in Xamarin.</p>
  <p><em><strong>MainActivity.cs</strong></em></p>
  <pre><code>[Activity(Label = &quot;CibMonitor&quot;, MainLauncher = true, Icon = &quot;@drawable/icon&quot;)]
      public class MainActivity : AppCompatActivity
      {
          RecyclerView recyclerView;
          RecyclerView.LayoutManager layoutManager;
          ConnectionItemsAdapter adapter;
          ConnectionItem[] connectionItems;
  
          protected override void OnCreate(Bundle bundle)
          {
              base.OnCreate(bundle);
              SetContentView(Resource.Layout.Main);
  
              var ci = new ConnectionItem();
  
              //Get list from web service
              connectionItems = ci.GetList().ToArray();
  
              //Setup RecyclerView
              adapter = new ConnectionItemsAdapter(this, connectionItems);
  
              recyclerView = FindViewById&lt;RecyclerView&gt;(Resource.Id.recyclerView);
  
              recyclerView.SetAdapter(adapter);
  
              ChangedData();
          }
      }
  </code></pre>
  <p><em><strong>Update</strong></em>
  I created new method in activity class as York Shen suggested</p>
  <pre><code>void ChangedData()
  {
      Task.Delay(5000).ContinueWith(t =&gt;
      {
          var newData = ConnectionItem.GetList();
          adapter.RefreshItems(newData);
          ChangedData();
      }, TaskScheduler.FromCurrentSynchronizationContext());
  }
  </code></pre>
  <p>This is my update method in adapter class:</p>
  <pre><code>public void RefreshItems(List&lt;ConnectionItem&gt; newItems)
  {
      items.Clear();
      items = newItems;
      NotifyDataSetChanged();
  }
  </code></pre>
  <p>my app stops working, no exception only this message:<a href="https://i.stack.imgur.com/1t5BI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1t5BI.jpg" alt="enter image description here" /></a></p>