Microsoft Developer Network > 포럼 홈 > Visual C# General > ContextSwitchDeadlock was detected
질문하기질문하기
 

답변됨ContextSwitchDeadlock was detected

  • 2009년 11월 3일 화요일 오후 9:13Jon Q Jacobs 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    What can I do not to get this error? I can click continue, but I want this to run without intervention.
    Here is distilled code where this happens:

    OleDbConnection con = new OleDbConnection(cons);

    OleDbCommand acmd = con.CreateCommand();

    con.Open();

    foreach (string tab in Tabs)
    {

      TextFileReadsAndStringManipulation();

      acmd.CommandText = qry;
      OleDbDataReader rdr = acmd.ExecuteReader(); 

      while (rdr.Read())
      {
        for (int i = 0; i < flds.Length; i++)
        {
          string s = rdr.GetValue(i).ToString().Replace("&", "&amp;");
          s = s.Replace("<", "&lt;");
          flds[i] = s.Replace(">", "&gt;");
        }
        string arow = String.Format(row, flds);
        wks = wks.Replace(Here, arow);
      }
      rdr.Close();
    }

답변

모든 응답

  • 2009년 11월 3일 화요일 오후 9:27ScottyDoesKnow 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    It means your interface is busy for over a minute or something like that. What you should do is put your long calculations into a separate thread, like a backgroundworker. You could also just turn off the error:

    Debug -> Exceptions -> somewhere in there, i don't remember where
  • 2009년 11월 4일 수요일 오후 6:03Jon Q Jacobs 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Thanks,

    I found a similar question posted for vb, so
    I added Application.DoEvents() to be called about every 20th pass through the loop, and that took care of it.

    Jon