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

前端 未结 6 1118
栀梦
栀梦 2020-12-14 00:30

I am getting this error on code that used to work. I have not changed the code.

Here is the full error:

The CLR has been unable to transition

6条回答
  •  不知归路
    2020-12-14 00:52

    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");
    }
    

提交回复
热议问题