Is it possible to wrap a call using the TPL Library in .Net?
I want to do something like this
Task t1 = Task.Factory.StartNew(() => { dynamic result = FacebookApp.Get("me/videos/uploaded", parameters); });
But I get an HttpContext error, I am assuming this is because the FacebooApp.Get method is using this internally.
How can I wrap calls to the FB API into tasks to run in parellel on the server?
I forgot to mention I am using the Facebook C# SDK hence FacebookApp.Get
EDITED
I have been watching some pluralsight videos on the TPL library and went with the pattern in the picture below. As you said there is the main thread coming in from the Create Controller itself, but I still needed to spawn 4 separate network tasks to do the network calls in parallel. I fix the HttpContext error by not having the function that was being called in 4th task to not rely on HttpContext at all.
The net result for me now is a more highly performance method call as promised with parallel programming.

If you call to a web service, and don’t want to block the request thread, it’s better to go with asynchronous pages (Web Forms) or asynchronous controllers (MVC). If you spin up a
Taskand need the value returned from the task, you will still be waiting for that operation to complete, which still blocks the request thread.Note that since ASP.NET is multi-threaded by default, you shouldn’t spin up multiple threads within a single web request.
UPDATE:
See this SO answer about multi-threading in web applications for more info.