Managing Ports and Transfers in .NET
IAsyncResult ar;
String msg;
String textToWrite;
// Text to write to the port.
textToWrite = "hello, world";
// A value to pass to the callback routine (optional).
msg = DateTime.Now.ToString();
// Call a routine to write to the COM port.
ar = WriteToComPortDelegate1.BeginInvoke
(textToWrite, new AsyncCallback(WriteCompleted), msg);
The BeginInvoke method calls WriteToComPort, which is the routine named
in the declaration of WriteToComPortDelegate1:
Friend Function WriteToComPort(ByVal textToWrite As String) As Boolean
Dim success As Boolean
If myComPort.IsOpen Then
' Write the passed String to the port.
myComPort.Write(textToWrite)
success = True
End If
Return success
End Sub