PowerTCP FTP for .NET
Start Method
Example 



System.Threading.WaitCallback delegate specifying the method to execute.
Information to pass to the worker delegate method; can be null.
Start a worker thread and execute the specified delegate.
Syntax
Public Sub Start( _
   ByVal worker As WaitCallback, _
   ByVal state As Object _
) 
Dim instance As Ftp
Dim worker As WaitCallback
Dim state As Object
 
instance.Start(worker, state)
public void Start( 
   WaitCallback worker,
   object state
)
public:
void Start( 
   WaitCallback^ worker,
   Object^ state
) 

Parameters

worker
System.Threading.WaitCallback delegate specifying the method to execute.
state
Information to pass to the worker delegate method; can be null.
Remarks

This method provides a convenient way to execute any method on a worker thread. Applications with a UI thread can use this technique to execute methods (like List, Get, Put) on a worker thread that would "freeze" the UI if executed on the UI thread.

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

Internally, this method uses ThreadPool.QueueUserWorkItem to start a worker thread. This method is provided for convenience; the developer may of course use alternative methods for starting worker threads if more specialized use is required.

Example
This example demonstrates using the FTP control to obtain a directory listing from a remote server.
private void getListing()
{
    //Setup the Ftp session and then connect, authenticate, and retrieve a listing on a worker thread
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer;
    ftp1.Session.Username = myUsername;
    ftp1.Session.Password = myPassword;

    //Wire up the Listing event to receive the listing on the UI thread
    ftp1.Listing += new EventHandler<ListingEventArgs>(ftp1_Listing);

    //The Start method executes the listing operation on a worker thread so the UI is not blocked.
    //Worker thread Exceptions are automatically caught and marshaled to the Error event
    ftp1.Start(getListingWorker, null);
}

private void getListingWorker(object state)
{
    try
    {
        //Login to a server and get a listing
        ftp1.Connect();
        ftp1.Authenticate();
        Listing listing = ftp1.List("", "", ListType.Full);

        //Marshal the listing to the UI thread
        ftp1.Marshal(listing, "", null);
    }
    finally
    {
        //Logout of the server
        ftp1.Close();
    }
}

private void ftp1_Listing(object sender, ListingEventArgs e)
{
    //Add all the list entries in the listing to a listbox
    foreach (ListEntry entry in e.Listing)
        listBox1.Items.Add(entry.Text);
}
Private Sub getListing()
    'Setup the Ftp session and then connect, authenticate, and retrieve a listing on a worker thread
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer
    ftp1.Session.Username = myUsername
    ftp1.Session.Password = myPassword

    'Wire up the Listing event to receive the listing on the UI thread
    AddHandler ftp1.Listing, AddressOf ftp1_Listing

    'The Start method executes the listing operation on a worker thread so the UI is not blocked.
    'Worker thread Exceptions are automatically caught and marshaled to the Error event
    ftp1.Start(AddressOf getListingWorker, Nothing)
End Sub

Private Sub getListingWorker(ByVal state As Object)
    Try
        'Login to a server and get a listing
        ftp1.Connect()
        ftp1.Authenticate()
        Dim listing As Listing = ftp1.List("", "", ListType.Full)

        'Marshal the listing to the UI thread
        ftp1.Marshal(listing, "", Nothing)
    Catch ex As Exception
        ftp1.Marshal(ex)
    Finally
        'Logout of the server
        ftp1.Close()
    End Try
End Sub

Private Sub ftp1_Listing(ByVal sender As Object, ByVal e As ListingEventArgs)
    'Add all the list entries in the listing to a listbox
    For Each entry As ListEntry In e.Listing
        listBox1.Items.Add(entry.Text)
    Next entry
End Sub
See Also

Reference

Ftp Class
Ftp Members


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic