Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

October 26, 2007

Events not Firing for Asynchronous FTP (Background Upload/Downloads)

Question:
Having a problem with events not triggering on FTP .NET component. C# code attached below. Trying to trigger an OnEndUploadFile() event. however the event code never gets calls — even though the FTP send completes successfully.

Any help greatly appreciated.

        private void buttonFileUpload_Click(object sender, EventArgs e)
        {
            Chilkat.Ftp2 chilkatFTP = new Chilkat.Ftp2();
	
            chilkatFTP.OnEndUploadFile += new Chilkat.Ftp2.EndUploadFileEventHandler(chilkatFTP_OnEndUploadFile);
            chilkatFTP.EnableEvents = true;
	
            chilkatFTP.UnlockComponent("myUnlockCode");
	
            chilkatFTP.Hostname = "myftpserver.com";
            chilkatFTP.Username = "myLogin";
            chilkatFTP.Password = "myPassword";
            chilkatFTP.Port = 21;
	
            chilkatFTP.Connect();
            chilkatFTP.AsyncPutFileStart(textBox1.Text, "./FTP/" + Path.GetFileName(textBox1.Text));
        }
	
        void chilkatFTP_OnEndUploadFile(object sender, Chilkat.FtpTreeEventArgs args)
        {
            MessageBox.Show("Done");
            chilkatFTP.Disconnect();
        }

Answer:

The AsyncPutFileStart method starts a background thread to do the transfer. It’s not possible to fire an event from a background thread to the foreground thread. There are two possible solutions:

1) Your app should create a timer event that fires periodically to check the value of the AsyncFinished property. When it becomes true, then the background task is complete. Also, there is an example here ( http://www.chilkatsoft.com/p/p_301.asp ) that shows how to do progress monitoring with an asynchronous (background) operation.

or

2) Do the upload in the foreground by calling PutFile. However, set the HeartbeatMs property to a value such as 100 to receive AbortCheck events every 100 millisec. Within your AbortCheck event handler, you should call DoEvents to keep your UI active and responsive.


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.