Client not receiving on second run

Apr 29, 2009 at 4:27 PM
Hi, first of all - thanks a bunch for the code.

I use DdeClient.StartAdvise to get real-time streaming data from 3d party DDE server. The problem is that if I re-run application and subscribe to the same topic as on previous run - I dont receive anything.

I have to subscribe to a different topic every time to test my app. The only workaround I have is to close Visual Studio, run Excel and get data, close Excel, run VS again. Seems the fresh Excel run resets something what I missed in my app.

I am sure that I call DdeClient.Dispose method before I quit.

Could you please give me an idea in what direction to look?

Thank you
Jun 17, 2010 at 10:56 PM
Edited Jun 17, 2010 at 10:57 PM

I have a working solution for the problem. You need to StopAdvise() and Disconnect() before you exit the program. However when you exit the program without doing this you need to find a way to restart the advise loop. One way is to restart the DDE service which is not ideal.

Sample code:

 

using System;
using NDde.Client;

namespace NDdeTest
{
    class Program
    {
        static DdeClient _client;

        static void Main()
        {
            _client = new DdeClient("service", "topic");
            _client.Connect();
            _client.StartAdvise("item", 1, true, 1000);
            _client.Advise += OnAdvise;
            Console.WriteLine("Press ENTER to quit...");
            Console.ReadLine();
            _client.StopAdvise("item", 1000);
            _client.Disconnect();
        }

        private static void OnAdvise(object sender, DdeAdviseEventArgs args)
        {
            Console.WriteLine(args.Text);
        }
    }
}