PowerTCP FTP for .NET
Marshal(Listing,String,Object) Method
Example 



The listing to be marshaled.
Any message to be marshaled.
Any object to be marshaled.
Marshals a string and/or Listing to the UI thread.
Syntax
Public Overloads Sub Marshal( _
   ByVal listing As Listing, _
   ByVal message As String, _
   ByVal state As Object _
) 
Dim instance As Ftp
Dim listing As Listing
Dim message As String
Dim state As Object
 
instance.Marshal(listing, message, state)
public void Marshal( 
   Listing listing,
   string message,
   object state
)
public:
void Marshal( 
   Listing^ listing,
   String^ message,
   Object^ state
) 

Parameters

listing
The listing to be marshaled.
message
Any message to be marshaled.
state
Any object to be marshaled.
Remarks

This method is used to marshal a Listing from a worker thread to the UI thread for typical display purposes. It calls the OnListing method, which raises the Listing event.

See the SynchronizingObject property for information on updating UI controls in your event handler. Internally, SynchronizingObject.BeginInvoke is used to marshal data when the SynchronizingObject is not null, and Delegate.DynamicInvoke is used when SynchronizingObject is null. This method is provided for convenience; the developer may of course use alternative methods for marshaling data 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
Overload List


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