Reading incoming multipart content

When using this snippet the thread goes into some infinite loop.


// Handle multipart
if (Request.Content.IsMimeMultipartContent())
{
   IEnumerable parts
     = Request
       .Content
       .ReadAsMultipartAsync()
       .Result
       .Contents;
   foreach (var part in parts)
   {
      // Do stuff with the part
   }
}

You can use the following to prevent this:

        public HttpResponseMessage Post()
        {
            // Handle multipart
            if (Request.Content.IsMimeMultipartContent())
            {
                IEnumerable parts = null;

                Task.Factory
                    .StartNew(() => parts = Request.Content.ReadAsMultipartAsync().Result.Contents,
                        CancellationToken.None,
                        TaskCreationOptions.LongRunning, // guarantees separate thread
                        TaskScheduler.Default)
                    .Wait();

                foreach (var part in parts)
                {
                    // Do stuff with the part
                }
            }
            return Request.CreateResponse(HttpStatusCode.OK, "Yeah, some text here...");
        }

Node.js Eventstore

http://eventstore.js.org/

The project goal is to provide an eventstore implementation for node.js:

load and store events via EventStream object
event dispatching to your publisher (optional)
supported Dbs (inmemory, mongodb, redis, tingodb, azuretable)
snapshot support
query your events