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.Hostname = "myftpserver.com";
chilkatFTP.Username = "myLogin";
chilkatFTP.Password = "myPassword";
chilkatFTP.Port = 21;
chilkatFTP.AsyncPutFileStart(textBox1.Text, "./FTP/" + Path.GetFileName(textBox1.Text));
void chilkatFTP_OnEndUploadFile(object sender, Chilkat.FtpTreeEventArgs args)
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.
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.