Getting ContextSwitchDeadlock during synchronization RRS feed

  • Question

  • when i tried to sync two 2008 r2 sql databases im getting an unhandled exception 'ContextSwitchDeadlock was detected'.When  I first received the "DisconnectedContext was detected" message and I removed the breaking on exception from the Debug->Exceptions... window. But then I received "ContextSwitchDeadlock was detected". I removed this too and the UI came back to life. After some time it freezed again.

    ContextSwitchDeadlock was detected
    Message: The CLR has been unable to transition from COM context 0x3683e0 to COM context 0x368550 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

    and my sync code is,

     SqlSyncProvider RemoteProvider = new SqlSyncProvider(scopename, sqlDestinationConn);
                    SqlSyncProvider LocalProvider = new SqlSyncProvider(scopename, sqlSourceConn);
                    if (sqlDestinationConn.State != ConnectionState.Open && sqlSourceConn.State != ConnectionState.Open)
                    RemoteProvider.MemoryDataCacheSize = MemorySize;
                    LocalProvider.MemoryDataCacheSize = MemorySize;               
                    RemoteProvider.ApplicationTransactionSize = BatchSize;               
                    RemoteProvider.ChangesApplied += new EventHandler<DbChangesAppliedEventArgs>(RemoteProvider_ChangesApplied);              
                    SyncOrchestrator oOrchestrator = new SyncOrchestrator();               
                    oOrchestrator .RemoteProvider = RemoteProvider;
                    oOrchestrator .LocalProvider = LocalProvider;
                    oOrchestrator .Direction = SyncDirectionOrder.UploadAndDownload;  
                    textBox3.Text = "Starting sync.... " + DateTime.Now + Environment.NewLine + textBox3.Text;
    Thanks in advance..

    • Edited by sharon 5656 Tuesday, November 15, 2011 8:27 AM
    Tuesday, November 15, 2011 8:26 AM

All replies

  • just to clarify, ContextSwitchDeadlock  is still detected despite unchecking it from Debug->Exceptions?
    Tuesday, November 15, 2011 10:13 AM
  • Yes,Its still detecting after unchecking it from visual studio.
    Tuesday, November 15, 2011 12:31 PM
  • It worked when i put all sync works in background worker.
    • Proposed as answer by JuneT Wednesday, November 23, 2011 6:20 AM
    Wednesday, November 23, 2011 6:09 AM