为什么我的Excel的DDE调用是在使用线程池获得.NET应用程序的渲染层之后挂起的?

我发现了一个非常奇怪的问题,如果我使用ThreadPool获得.NET应用程序的渲染层,它将挂起一个非常简单的DDE调用。 在与Excel的DDE调用同时运行复杂的WPF应用程序时,发现问题。 我已经设法重现了几行代码,可以在下面find的问题。

C#.Net App

//Need to reference PresentationCore.dll class Program { private static int _renderTier; static void Main(string[] args) { ThreadPool.QueueUserWorkItem(x => { _renderTier = RenderCapability.Tier; Console.WriteLine(_renderTier); }); Console.ReadLine(); } } 

Excel DDEmacros。

 Sub Using_DDE1() ' Dimension the variables. Dim Chan As Integer Dim RequestItems As Variant ' Start a channel to Word using the System topic. Chan = DDEInitiate("WinWord", "System") ' Requesting information from Word using the Formats item ' this will return a one dimensional array. RequestItems = DDERequest(Chan, "Formats") ' Uses a FOR loop to cycle through the array and display in a message box. For i = LBound(RequestItems) To 3 MsgBox RequestItems(i) Next i ' Terminate the DDE channel. DDETerminate Chan End Sub 

运行macros时,会自动运行3个消息框。 如果我尝试在c#应用程序运行时运行macros,它将挂起对DDEInitiate的调用。 只要c#应用程序closures,excel就会恢复生机。 从主线程获取渲染层不会导致问题。 我也注意到,如果debugging器暂停,即使没有调用渲染层,macros也会挂起。

用Excel 2003,.Net3.5&.Net4和Windows 7与Excel 2010,.Net3.5和.Net4一起使用Windows XP复制的问题。

任何想法为什么发生这种情况? 这是一个与PresentationCore.dll的错误?

谢谢你的帮助

[更新]

改变机器的渲染层似乎释放这个'锁'(我不得不稍后移动窗口)。 我通过启动NetMeeting来更改渲染层,但可以通过强制显卡在显示属性中使用软件渲染来完成。

也许这有助于:

如果基于Windows 2000或基于Windows XP的计算机上运行的另一个程序不能正确处理Windows消息循环,则使用DDE的程序将停止响应。

你可以在这里find它。

这只发生在32位Windows中,只有DDE客户端受到影响。 为了build立连接,应用程序向所有顶级窗口广播消息。 如果窗口不在同一个线程上,则该消息实际上被发送到收件人队列,并且调用者被阻止。 如果收件人没有消息队列,则调用线程将被永久阻止。 微软已经承认这是一个错误。

更多详细信息请参阅知识库文章Q136218错误:DdeConnect永不返回。