The CLR has been unable to transition from COM context […] for 60 seconds

The CLR has been unable to transition from COM context […] for 60 seconds

I got this problem while working with a large database and it made the UI freeze for a long period. So I put the codes in a BackgroundWorker and now the problem is gone. thanks to @i_am_jorf

What this message is telling you is that whatever it's trying to do, it's doing it on the UI thread and not in a nice way, and that seems to be taking a long time.

private void btnConvert_Click(object sender, EventArgs e)
{
  Cursor = Cursors.WaitCursor;
  bgwConvert.RunWorkerAsync();
}

private void bgwConvert_DoWork(object sender, DoWorkEventArgs e)
{
  //My taking-lots-of-time codes
}

private void bgwConvert_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
  Cursor = Cursors.Default;
  MessageBox.Show("Done");
}

我遇到的问题,也是ui太长时间没有响应。需要新开一个线程来处理耗时操作

原文地址:https://www.cnblogs.com/chucklu/p/14395819.html