First, you're using an async method, so you'll need to await it;
01 MemoryStream m = new MemoryStream();
02 await Request.Files[0].InputStream.CopyToAsync(m);
03 ToDo(NameOfFile, m);
Or just use CopyTo()
instead. If you don't await on line 02, the work won't be finished by line 03.
Second, since the inputstream belongs to the Request, I'd bet that, once the web request is finished, everything about it is cleaned up, and your thread is trying to copy the request content too late.
Can you simply move lines 01 and 02 into the main thread of the request? Something more like;
public Task<ActionResult> DoFileStuff()
{
MemoryStream m = new MemoryStream();
await Request.Files[0].InputStream.CopyToAsync(m);
new Thread(DoMoreWork).Start();
}
You get the idea - load the request stream into the memory stream before the Action Method finishes.