5

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.

Tom Webster
  • 350
  • 1
  • 9

1 Answers1

3

Maybe this helps:

If another program that is running on the Windows 2000-based or on the Windows XP-based computer does not correctly process an Windows message loop, the program that uses DDE stops responding.

You can find it here.

This only happens in 32-bit Windows, and only DDE clients are affected. To make a connection, an application broadcasts a message to all top level windows. If the window is not on the same thread, the message is actually posted to the recipients queue and the caller is blocked. If the recipient has no message queue the calling thread is permanently blocked. Microsoft has acknowledged that this is a bug.

Further details are in the Knowledgebase article Q136218 BUG: DdeConnect Never Returns.

Jacob Seleznev
  • 8,013
  • 3
  • 24
  • 34