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.