DdeContext Class

NDde

Dynamic Data Exchange Library for .NET

DdeContext Class

This provides an execution context for DdeClient and DdeServer.

For a list of all members of this type, see DdeContext Members.

System.Object    DdeContext

public class DdeContext : IDisposable, ISynchronizeInvoke

Thread Safety

This type is safe for multithreaded operations.

Remarks

This class provides a context for DDE activity. All DdeClient and DdeServer objects must be associated with an instance of this class. If one is not specified in their constructors then a default instance of this class is used. This class must be initialized before it can begin sending and receiving DDE messages. This happens automatically upon its first use by a DdeClient or DdeServer. An application can call Initialize to make the initialization process occur immediately. This is useful when a calling application expects this class to raise the Register and Unregister events or invoke the ITransactionFilter.PreFilterTransaction method before being used by a DdeClient or DdeServer.

Since forms and controls implement ISynchronizeInvoke they can be used as the synchronizing object for this class. When an instance of this class is created to use a form or control as the synchronizing object it will use the UI thread for execution. This is the preferred way of creating an instance of this class when used in a windows application since it avoids multithreaded synchronization issues and cross thread marshaling. When an instance of this class is created without specifying a synchronizing object it will create and manage its own thread for execution. This is convenient if you wish to use this library in a console or service application, but with the added cost of cross thread marshaling and the potential for deadlocking application threads.

Events are invoked on the thread hosting the DdeContext. All operations must be marshaled onto the thread hosting the DdeContext. Method calls will block until that thread becomes available. An exception will be generated if the thread does not become available in a timely manner.

Example

The following example demonstrates how to instantiate a DdeContext in a console application.

[C#]
using System;
using NDde.Advanced;
 
public class Example 
{
    public static void Main()
    {
        // Create a context that uses a dedicated thread for DDE message pumping.
        DdeContext context = new DdeContext();
    }
}
[Visual Basic]
            Imports NDde.Advanced

            Public Class Example
                Public Shared Sub Main()
                    ' Create a context that uses a dedicated thread for DDE message pumping.
                    Dim context As DdeContext = New DdeContext()
                End Sub
            End Class
            
The following example demonstrates how to instantiate a DdeContext in a windows application.
[C#]
using System;
using NDde.Advanced;
 
public class Example : Form
{
    // Standard Form code omitted for brevity.
    
    private DdeContext context = null;
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        // Create a context that uses the UI thread for DDE message pumping.
        context = new DdeContext(this);
    }
}
[Visual Basic]
Imports NDde.Advanced

Public Class Example
    Inherits Form
    
    Private context as DdeContext = Nothing
    
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Create a context that uses the UI thread for DDE message pumping.
        context = New DdeContext(Me)
    End Sub
End Class

Requirements

Namespace: NDde.Advanced

Assembly: NDde (in NDde.dll)

See Also

DdeContext Members | NDde.Advanced Namespace