Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 10


Create a routine with the same parameter(s) as the delegate:

 Private Sub AccessFormMarshal(ByVal textToDisplay As String)


' The parameter(s) to pass to the form.

Dim args() As Object = {textToDisplay}

' The AccessForm routine contains the code that accesses the form.

Dim AccessFormMarshalDelegate1 As _
New AccessFormMarshalDelegate(AddressOf AccessForm)

' Call AccessForm, passing the parameters in args.

MyBase.Invoke(AccessFormMarshalDelegate1, args)

End Sub

 internal void AccessFormMarshal(string textToDisplay)
{
// The parameter(s) to pass to the form.


object[] args = {textToDisplay};

AccessFormMarshalDelegate AccessFormMarshalDelegate1 = null;

// The AccessForm routine contains the code that accesses the form.

AccessFormMarshalDelegate1 = new AccessFormMarshalDelegate(AccessForm);

// Call AccessForm, passing the parameters in args.

base.Invoke(AccessFormMarshalDelegate1, args);
}
Create the routine that accesses the form. This example appends the passed text
to a text box (txtUserDisplay) on the form:

 Private Sub AccessForm(ByVal textToDisplay As String)


txtUserDisplay.AppendText(textToDisplay)
End Sub
Free download pdf