Dart.Ftp Namespace > Ftp Class > Marshal Method : Marshal(Listing,String,Object) Method |
Public Overloads Sub Marshal( _ ByVal listing As Listing, _ ByVal message As String, _ ByVal state As Object _ )
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.
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