title: Start thread returns System.InvalidOperationException: The current SynchronizationContext may not be used as a TaskScheduler
body: <p>I add a dashboard <code>devexpress</code> that run a stored procedure and it takes a long time. So I created a simple thread in my application in <code>form_load</code></p>
  
  <pre><code>public void LoadDashboard()
  {
      using (Stream s = new MemoryStream(Encoding.Default.GetBytes(Resource.Dashboard.MaterialDashboard1)))
      {
           s.Position = 0;
           dashboardViewer1.LoadDashboard(s);
      }
  }
  
  private void frmMaterialDashboard_Load(object sender, EventArgs e)
  {
      Thread newth=new Thread(LoadDashboard);
      newth.Start();
  
      int UserId = int.Parse(Configuration.AccountDetail.UserId.ToString());
      lblUserName.Caption = _userRepository.Get().Where(i =&gt; i.Id == UserId).First().FullName;
  
      alertControl1.Show(this, "Welcome","Welcome to SPMS Mr."+_userRepository.FindById(Configuration.AccountDetail.UserId).First().FullName +"\n Server time:"+DateTime.Now);
  }
  </code></pre>
  
  <p>But when I run my application I get this error :</p>
  
  <blockquote>
    <p>An unhandled exception of type 'DevExpress.DashboardCommon.DashboardInternalException' occurred in DevExpress.Dashboard.v15.2.Win.dll  </p>
    
    <p>Additional information: Internal error. Please contact the application vendor or your system administrator and provide the following information.</p>
    
    <p>System.InvalidOperationException: The current SynchronizationContext may not be used as a TaskScheduler.</p>
    
    <p>at System.Threading.Tasks.SynchronizationContextTaskScheduler..ctor()<br>
    at DevExpress.DashboardWin.Native.WinDashboardService.RequestCustomizationServices(RequestCustomizationServicesEventArgs e)<br>
    at DevExpress.DashboardCommon.Service.DashboardService.DevExpress.DashboardCommon.Service.IDashboardServiceAdminHandlers.OnRequestCustomizationServices(Object sender, RequestCustomizationServicesEventArgs e)<br>
    at DevExpress.DashboardCommon.Server.DashboardSession.CreateDataLoaderParameters(ReloadDataArgs args)
    at DevExpress.DashboardCommon.Server.DashboardSession.CreateDataLoader(ReloadDataArgs args)<br>
    at DevExpress.DashboardCommon.Server.DashboardSession.LoadData(IEnumerable<code>1 dataSourceComponentNames, ReloadDataArgs args)<br>
    at DevExpress.DashboardCommon.Server.DashboardSession.ReloadData(IEnumerable</code>1 dataSourceComponentNames, ReloadDataArgs args)<br>
    at DevExpress.DashboardCommon.Server.DashboardSession.Initialize(DashboardSessionState state, Boolean isDesignMode)<br>
    at DevExpress.DashboardCommon.Service.DashboardServiceOperation`1.Execute(DashboardServiceResult result)  </p>
  </blockquote>
  
  <p><strong>Updated</strong> </p>
  
  <p>I change my code like this, it works without any error and the data is shown but without any async operation and I have to wait to load data </p>
  
  <pre><code>public async Task&lt;Stream&gt; LoadDashboard()
  {
      Stream s = new MemoryStream(Encoding.Default.GetBytes(Resource.Dashboard));
      s.Position = 0;
      return s;
  }
  
  private async void frmMaterialDashboard_Load(object sender, EventArgs e)
  {
      Stream dashboardData = await LoadDashboard();
      dashboardViewer1.LoadDashboard(dashboardData);
  
      int UserId = int.Parse(Configuration.AccountDetail.UserId.ToString());
      lblUserName.Caption = _userRepository.Get().Where(i =&gt; i.Id == UserId).First().FullName;
      alertControl1.Show(this, "Welcome","Welcome to SPMS Mr."+_userRepository.FindById(Configuration.AccountDetail.UserId).First().FullName +"\n Server time:"+DateTime.Now);
  }
  </code></pre>