为什么在我使用线程池获得 .Net 应用程序的渲染层后,来自 Excel 的 DDE 调用会挂起?
我发现了一个非常奇怪的问题,如果我使用 ThreadPool 获取 .Net 应用程序的渲染层,它将挂起来自 Excel 的非常简单的 DDE 调用。当从 Excel 调用 DDE 的同时运行复杂的 WPF 应用程序时,会出现此问题。我已经设法用几行代码重现了这个问题,如下所示。
C# .Net 应用程序
//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 DDE 宏。
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
单独运行该宏时,会弹出 3 个消息框。如果我尝试在 C# 应用程序运行时运行宏,它将挂起对 DDEInitiate 的调用。一旦 C# 应用程序关闭,Excel 就会恢复活力。从主线程获取渲染层不会导致问题。我还注意到,如果调试器暂停,即使尚未调用获取渲染层,宏也会挂起。
使用带有 Excel 2003、.Net3.5 和 .Net3.5 的 Windows Xp 复制问题.Net4 和 Windows 7 以及 Excel 2010、.Net3.5 和.Net4。
知道为什么会发生这种情况吗?这是PresentationCore.dll 的错误吗?
感谢您的帮助
[更新]
更改机器的渲染层似乎可以释放此“锁定”(之后我不得不稍微移动窗口)。我通过启动 NetMeeting 来更改渲染层,但这可以通过强制显卡在显示属性中使用软件渲染来完成。
I have found a very strange issue where if I get the Rendering Tier of a .Net App using the ThreadPool it will hang a very simple DDE call from Excel. The issue was seen when running a complex WPF app at the same time as the DDE call from Excel. I have managed to reproduce the issue in a few line of code which can be found below.
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();
}
}
The Excel DDE Macro.
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
Running the macro will bring up 3 message boxes when running on its own. If I try running the macro while the c# app is running it will hang on the call to DDEInitiate. As soon as the c# app is closed excel comes back to life. Getting the Rendering Tier from the Main thread does not cause the issue. I also noticed that if the debugger is paused the macro will hang even if the call to get the rendering tier hasn't been made.
Issue replicated using Windows Xp with Excel 2003, .Net3.5 & .Net4 and Windows 7 with Excel 2010, .Net3.5 & .Net4.
Any idea why this is happening? Is this a bug with the PresentationCore.dll?
Thanks for your help
[Update]
Changing the Rendering Tier of the Machine seems to release this 'lock' (I had to move the windows around a bit afterwards). I was changing the rendering Tier by starting NetMeeting but it can be done by forcing your Graphics Card to use software rendering in Display Properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这有帮助:
您可以在此处找到它。
更多详细信息请参阅知识库文章 Q136218 BUG:DdeConnect永不回归。
Maybe this helps:
You can find it here.
Further details are in the Knowledgebase article Q136218 BUG: DdeConnect Never Returns.