Calling a void async. - Event based pattern, or another method?

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-03-23T16:29:32Z Indexed on 2010/03/23 18:23 UTC
Read the original article Hit count: 266

Filed under:
|

I have a class that basically stores files in amazon s3. Here is what it looks like (simplified)

public class S3FileStore
{
   public void PutFile(string ID, Stream content)
      {
          //do stuff
      }
}

In my client app, I want to be able to call:

var s3 = new() S3FileStore();
s3.PutFile ("myId", File.OpenRead(@"C:\myFile1"));
s3.PutFile ("myId", File.OpenRead(@"C:\myFile2"));
s3.PutFile ("myId", File.OpenRead(@"C:\myFile3"));

I want this to be an asynchronous operation - I want the S3FileStore to handle this (i don't want my caller to have to execute PutFile asynchronously so to speak) but, i want to be able to trap exceptions / tell if the operation completed for each file.

I've looked at event based async calls, especially this: http://blogs.windowsclient.net/rendle/archive/2008/11/04/functional-shortcuts-2-event-based-asynchronous-pattern.aspx

However, I can't see how to call my PutFile (void) method?

Are there any better examples?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asynchronous