tags:

views:

39

answers:

0

Hello,

I am using NDde for DDE transactions. I am trying to create multiple instances of DdeClient using threads. For this example, we will assume there is 3 threads. If I try it with a single thread, it works. But anything more than 2 returns me an error whereby it failed to initiate an advise loop. The question is why would it not work when it is multi threaded and each thread have their own "advise" handler? Any help will be greatful

What I did: 1) In a loop, I called Thread t = new Thread(CreateDdeThread); which is linked to private void CreateDdeThread(object data) 2) In private void CreateDdeThread(object data), I create a DdeClient with their necessary eventhandlers.

private void CreateDdeThread(object data)
{
    Console.WriteLine("CreateDdeThread");
    Spark spark = (Spark)data;
    DdeClient ddeClient = new DdeClient("Client", spark.GetClient() + ".Name");
    ddeClient.Disconnected +=new 
        EventHandler<DdeDisconnectedEventArgs>(OnDisconnected);
    ddeClient.Connect();
    ddeClient.Advise += new EventHandler<DdeAdviseEventArgs>(OnAdvise);
    ddeClient.StartAdvise(
        "Address." + spark.GetStreet(), 1, true, true, 60000, ddeClient);
}

private void OnAdvise(object sender, DdeAdviseEventArgs args)
{
    string[] p = args.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
    foreach (string s in p)
    {
        Console.WriteLine(s);
    }
}