Visual Basic (Declaration) | |
---|---|
Public Sub Start( _ ByVal worker As RshThreadStart, _ ByVal state As Object _ ) |
Visual Basic (Usage) | ![]() |
---|---|
Dim instance As Rsh Dim worker As RshThreadStart Dim state As Object instance.Start(worker, state) |
C# | |
---|---|
public void Start( RshThreadStart worker, object state ) |
Managed Extensions for C++ | |
---|---|
public: void Start( RshThreadStart* worker, Object* state ) |
C++/CLI | |
---|---|
public: void Start( RshThreadStart^ worker, Object^ state ) |
Parameters
- worker
- RshThreadStart delegate specifying the function to execute.
- state
- Information to pass to the worker delegate function; can be null.
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# | ![]() |
---|---|
//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 Basic | ![]() |
---|---|
'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 |
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.
Target Platforms: Microsoft .NET Framework 2.0