G
Guest
Hi,
I am using .BeginInvoke to make an asynchronous call to a function, and
passing in a AsyncCallback, so client gets notification when method
completes, relevant code is provided below:
AsyncCallback callback = new AsyncCallback(this.NotifyIt);
FtpClient ftpC = new FtpClient(FtpServer, FtpUserName, FtpPassword);
private void button4_Click_1(object sender, System.EventArgs e)
{
ftpC.ChangeDir(remotePath);
ftpC.BeginGetFileSize("test.txt", callback);
}
//callback function
private void NotifyIt(IAsyncResult result)
{
//close connection
ftpC.Close();
MessageBox.Show(result.IsCompleted.ToString());
}
//Async Delegate implementation
private delegate Int64 GetFileSizeCallback(String fileName);
public System.IAsyncResult BeginGetFileSize( String fileName,
System.AsyncCallback callback )
{
GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
return ftpCallback.BeginInvoke(fileName, callback);
}
All works great but I can't figure out how to pass in a return value from
GetFileSize which is Int64 to the call back function. Can it be done at all,
or am I on the wrong page all together?
I am using .BeginInvoke to make an asynchronous call to a function, and
passing in a AsyncCallback, so client gets notification when method
completes, relevant code is provided below:
AsyncCallback callback = new AsyncCallback(this.NotifyIt);
FtpClient ftpC = new FtpClient(FtpServer, FtpUserName, FtpPassword);
private void button4_Click_1(object sender, System.EventArgs e)
{
ftpC.ChangeDir(remotePath);
ftpC.BeginGetFileSize("test.txt", callback);
}
//callback function
private void NotifyIt(IAsyncResult result)
{
//close connection
ftpC.Close();
MessageBox.Show(result.IsCompleted.ToString());
}
//Async Delegate implementation
private delegate Int64 GetFileSizeCallback(String fileName);
public System.IAsyncResult BeginGetFileSize( String fileName,
System.AsyncCallback callback )
{
GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
return ftpCallback.BeginInvoke(fileName, callback);
}
All works great but I can't figure out how to pass in a return value from
GetFileSize which is Int64 to the call back function. Can it be done at all,
or am I on the wrong page all together?