Running an asynchronous operation triggered by an ASP.NET web page request

I have an asynchronous operation that for various reasons needs to be triggered using an HTTP call to an ASP.NET web page. When my page is requested, it should start this operation and immediately return an acknowledgment to the client. This method is also exposed via a WCF web service, and it works perfectly. On … Read more

How to limit the Maximum number of parallel tasks in c#

I have a collection of 1000 input message to process. I’m looping the input collection and starting the new task for each message to get processed. //Assume this messages collection contains 1000 items var messages = new List<string>(); foreach (var msg in messages) { Task.Factory.StartNew(() => { Process(msg); }); } Can we guess how many … Read more

Test if function or method is normal or asynchronous

How can I find out if a function or method is a normal function or an async function? I would like my code to automatically support normal or async callbacks and need a way to test what type of function is passed. async def exampleAsyncCb(): pass def exampleNomralCb(): pass def isAsync(someFunc): #do cool dynamic python … Read more

Task.Factory.StartNew vs new Task

Does anyone know if there is any difference between doing Task.Factory.StartNew vs new Task followed by calling Start on the task. Looking at reflector there doesn’t seem to be much difference. So perhaps the only difference is that Task.Factory.StartNewreturns a task that is already started. Is this correct? I know that Task.Factory.StartNewand Task.Run have different … Read more

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

I’m trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource. One thing that isn’t clear to me is when to use SetResult, SetException, and SetCancel versus TrySetResult, TrySetException and TrySetCancel. This is what MSDN has to say: This operation will return false … Read more