How to pass in a value into AsyncCallback function

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top