title: C#: Task.Run execute on main thread
body: <p>I am using monotouch/Xamarin for an iOS app.</p>
  
  <p>The documentation for <a href="https://msdn.microsoft.com/en-us/library/hh195051(v=vs.110).aspx" rel="nofollow"><code>Task.Run</code></a> states:</p>
  
  <blockquote>
    <p>Queues the specified work to run on the ThreadPool and returns a task
    handle for that work.</p>
  </blockquote>
  
  <p>Which essentially indicates that it could run on any thread <code>ThreadPool</code>.</p>
  
  <p>I want to do something like:</p>
  
  <pre><code>Task.Run(async () =&gt; await PerformTask());
  </code></pre>
  
  <p>but have it run on the main thread. Normally I would write it using <a href="http://developer.xamarin.com/api/member/MonoTouch.Foundation.NSObject.BeginInvokeOnMainThread(MonoTouch.Foundation.NSAction)/" rel="nofollow"><code>BeginInvokeOnMainThread</code></a> as follows:</p>
  
  <pre><code>BeginInvokeOnMainThread(async () =&gt; await PerformTask());
  </code></pre>
  
  <p>But I am doing this in shared code and do not want to use iOS specific calls. Is there a way for me to tell Task.Run() to invoke the action on the main thread?</p>