VS 2008 でプログラムをデバッグしているときに、次のエラーに遭遇しました。
CLR は、60 秒間、COM コンテキスト 0x34fc1a0 から COM コンテキスト 0x34fc258 に移行できませんでした。宛先コンテキスト/アパートメントを所有するスレッドは、非ポンピング待機を行っているか、Windows メッセージをポンピングせずに非常に長時間実行されている操作を処理している可能性があります。この状況は通常、パフォーマンスに悪影響を及ぼし、アプリケーションが応答しなくなったり、メモリ使用量が時間の経過とともに継続的に蓄積したりする可能性さえあります。これを避けるには
コードには単純な C# タイマーしか含まれていませんが、デッドロックしているように見えます: 以下のスニペットを参照してください:
private void RequestWork()
{
// The timer will be re-intialised if there are still no wating jobs in the database
StopTimer();
// assign all the threads some work
InitialiseTimer();
}
/// <summary>
/// Initialise a timer with a timer interval configured from app.config. Enable the timer and
/// register an appropriate event handler
/// </summary>
private void InitialiseTimer()
{
if (m_Timer == null)
{
// look up the default backoff time from the config
string backOffInt = ConfigurationSettings.AppSettings["BackOffInterval"];
int backoffInterval = 1000;
m_Timer = new System.Timers.Timer();
// set the timer interval to 5 seconds
m_Timer.Interval = backoffInterval;
m_Timer.Elapsed += new ElapsedEventHandler(m_Timer_Elapsed);
}
m_Timer.Enabled = true;
}
private void StopTimer()
{
if (m_Timer != null)
{
m_Timer.Enabled = false;
}
}
void m_Timer_Elapsed(object p_Sender, ElapsedEventArgs p_E)
{
RequestWork();
}
タイマーが実行され、経過してから再び初期化される必要があることを知っている限り、デッドロックのローカルな理由はわかりません。
このエラーメッセージをオフにする方法は知っていますが、これは解決策ではなく、問題を隠していると感じています。