PowerTCP Emulation for .NET CF
Start Method
See Also  Example Send comments on this topic.
Dart.Emulation Namespace > Telnet Class : Start Method




worker
TelnetThreadStart delegate specifying the function to execute.
state
Information to pass to the worker delegate function; can be null.
Starts a worker thread on which the specified delegate function executes.

Syntax

Visual Basic (Declaration) 
Public Sub Start( _
   ByVal worker As TelnetThreadStart, _
   ByVal state As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As Telnet
Dim worker As TelnetThreadStart
Dim state As Object
 
instance.Start(worker, state)
C# 
public void Start( 
   TelnetThreadStart worker,
   object state
)
Managed Extensions for C++ 
public: void Start( 
   TelnetThreadStart* worker,
   Object* state
) 
C++/CLI 
public:
void Start( 
   TelnetThreadStart^ worker,
   Object^ state
) 

Parameters

worker
TelnetThreadStart delegate specifying the function to execute.
state
Information to pass to the worker delegate function; can be null.

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 provides an easy means for executing blocking functions on a worker thread. Applications with a UI thread should use this technique to execute processes (like Connect and Read) that can block the UI thread.

The state parameter can be null for cases in which no state information needs to be passed to the worker delegate function.

Unhandled exceptions occurring on the worker thread will be caught and reported in the Error event.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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