PowerTCP Telnet for .NET CF
Marshal(Data,Object) Method
See Also  Example Send comments on this topic.
Dart.Common Namespace > TcpBase Class > Marshal Method : Marshal(Data,Object) Method




data
The data to be marshaled.
state
State information to be marshaled.
Marshals data to the UI thread.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub Marshal( _
   ByVal data As Data, _
   ByVal state As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As TcpBase
Dim data As Data
Dim state As Object
 
instance.Marshal(data, state)
C# 
public void Marshal( 
   Data data,
   object state
)
Managed Extensions for C++ 
public: void Marshal( 
   Data* data,
   Object* state
) 
C++/CLI 
public:
void Marshal( 
   Data^ data,
   Object^ state
) 

Parameters

data
The data to be marshaled.
state
State information to be marshaled.

Example

This example demonstrates execution of a looping Read on a worker thread, and marshaling the data back to the UI. This specific example uses the Telnet component, but the code is the same for any component that derives from TcpBase.
C#Copy Code
//Receive data on a separate thread
telnet1.Start(receiveData, null);

private void receiveData(Telnet telnet, object notUsed)
{
	//Receive data when it is sent by the remote host
	byte[] buffer = new byte[1024];
	while (telnet.State != Dart.Common.ConnectionState.Closed)
		telnet.Marshal(telnet.Read(buffer, 0, 1024), null);
}
    
private void telnet1_Data(object sender, DataEventArgs e)
{
	//Whenever data is received, display it
	textDisplay.Text + e.Data.ToString();
}
Visual BasicCopy Code
'Receive data on a separate thread
telnet.Start(AddressOf receiveData, Nothing)
	
Private Sub receiveData(ByVal telnet As Telnet, ByVal notUsed As Object)
	'Receive data when it is sent by the remote host
	Dim buffer() As Byte = New Byte(1023){}
	Do While telnet.State <> ConnectionState.Closed
		telnet.Marshal(telnet.Read(buffer, 0, 1024), Nothing)
	Loop
End Sub
	
Private Sub telnet1_Data(ByVal sender As Object, ByVal e As DataEventArgs) Handles telnet1.Read
	'Whenever data is received, display it
	textDisplay.Text = e.Data.ToString()
End Sub

Remarks

This method is used to marshal data from a worker thread back to the UI thread for typical display purposes. It calls the OnData method, which raises the Data event.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.