Example #1
0
        static void Main(string[] args)
        {
            // Wait for the user to press ENTER before proceding.
            Console.WriteLine("The Server sample must be running before the client can connect.");
            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
            try
            {
                // Create a client that connects to 'myapp|mytopic'. 
                using (DdeClient client = new DdeClient("myapp", "mytopic"))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    // Synchronous Execute Operation
                    client.Execute("mycommand", 60000);

                    // Synchronous Poke Operation
                    client.Poke("myitem", DateTime.Now.ToString(), 60000);

                    // Syncronous Request Operation
                    Console.WriteLine("Request: " + client.Request("myitem", 60000));

                    // Asynchronous Execute Operation
                    client.BeginExecute("mycommand", OnExecuteComplete, client);

                    // Asynchronous Poke Operation
                    client.BeginPoke("myitem", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client);

                    // Asynchronous Request Operation
                    client.BeginRequest("myitem", 1, OnRequestComplete, client);

                    // Advise Loop
                    client.StartAdvise("myitem", 1, true, 60000);
                    client.Advise += OnAdvise;

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press ENTER to quit...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }
        }
 public void Test_EndRequest_After_Dispose()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
             IAsyncResult ar = client.BeginRequest(ItemName, 1, null, null);
             Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false));
             client.Dispose();
             byte[] data = client.EndRequest(ar);
         }
     }
 }
 public void Test_BeginRequest_Before_Connect()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             IAsyncResult ar = client.BeginRequest(ItemName, 1, null, null);
         }
     }
 }