在同步期间获取ContextSwitchDeadlock [英] Getting ContextSwitchDeadlock during synchronization

查看:80
本文介绍了在同步期间获取ContextSwitchDeadlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试同步两个2008 r2 sql数据库时,我得到一个未处理的异常'检测到ContextSwitchDeadlock'。当我第一次收到"检测到DisconnectedContext"时消息,我从Debug-> Exceptions ...
窗口中删除了异常。但后来我收到了"检测到ContextSwitchDeadlock"。我也删除了这个,UI恢复了生机。一段时间后它再次冻结。

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

消息:CLR无法从COM上下文0x3683e0转换到COM上下文0x368550 60秒。拥有目标上下文/公寓的线程很可能是在非抽空等待或处理非常长时间运行的操作
而不抽取Windows消息。这种情况通常会对性能产生负面影响,甚至可能导致应用程序变得无响应或内存使用量随时间不断累积。为了避免这个问题,所有单线程单元
(STA)线程都应该使用抽取等待原语(例如CoWaitForMultipleHandles)并在长时间运行操作期间定期泵送消息。

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.

和我的同步代码是,

 SqlSyncProvider RemoteProvider = new SqlSyncProvider(scopename, sqlDestinationConn);
                SqlSyncProvider LocalProvider = new SqlSyncProvider(scopename, sqlSourceConn);
                if (sqlDestinationConn.State != ConnectionState.Open && sqlSourceConn.State != ConnectionState.Open)
                {
                    sqlDestinationConn.Open();
                    sqlSourceConn.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;
                textBox3.ScrollToCaret();
                textBox3.Refresh();
                ShowStatistics(oOrchestrator.Synchronize());


Thanks in advance..







推荐答案

只是为了澄清,ContextSwitchDeadlock 尽管从Debug-> Exceptions中取消选中它仍然被检测到?
just to clarify, ContextSwitchDeadlock  is still detected despite unchecking it from Debug->Exceptions?


这篇关于在同步期间获取ContextSwitchDeadlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆