Tagged Questions
0
votes
1answer
38 views
How to run MSDN code example “How to: Create Pre-Computed Tasks”?
Trying to run C# code example "How to: Create Pre-Computed Tasks" (MSDN) in .NET 4.0 Async CTP, having made changes:
Task.FromResult ---> TaskEx.FromResult
Task.FromResult ---> ...
2
votes
2answers
52 views
TaskEx.WhenAll and Exceptions
I'm constrained to using the .NET 4.0 framework and Async CTP Extensions to do something like the following:
var dataTasks = _tasks.Select(t => t.GetData(keys));
var results = ...
1
vote
2answers
296 views
Fire-forget and One-Way Calls in ASP.NET WebApi
I totally understand that HTTP world is not the best choice for one-way calls and that WebApi is designed best for HTTP verbose communications. No doubt, WCF is the winner here. But, what if you ...
4
votes
2answers
694 views
Alternative for Task.Wait in UI thread
I know it is bad to call Task.Wait in UI thread. It causes a deadlock. Please refer to
Constructor invoke async method
Await, and UI, and deadlocks! Oh my!
Take the following code:
public ...
10
votes
2answers
1k views
can not await async lambda
Consider this,
Task task = new Task (async () =>{
await TaskEx.Delay(1000);
});
task.Start();
task.Wait();
The call task.Wait() does not wait for the task completion and the next line is ...
3
votes
1answer
278 views
How to correctly implement a TAP method?
I want to provide a task-based asynchronous pattern-style method. When awaiting the method, I could not find any difference between these two ways of providing the method:
// GetStats is a delegate ...
4
votes
4answers
842 views
.NET 4 equivalent of Task.WhenAll()
In .NET 4, is there any functional equivalent to .NET 4.5's System.Threading.Tasks.Task.WhenAll()?
The goal is to wrap up multiple async tasks into a single one that is completed when all of its ...
0
votes
1answer
304 views
An Async Task issue - Cross-threaded access to forms
The Simplified 7 Steps :
[MainForm] User Clicks btnAdd Button
AddForm will be shown
[AddForm] btnCreate is clicked
within the btnCreate_Click we run AddProductProcess with an awaiter
* We will close ...
11
votes
5answers
2k views
How to limit the amount of concurrent async I/O operations?
// let's say there is a list of 1000+ URLs
string[] urls = { "http://google.com", "http://yahoo.com", ... };
// now let's send HTTP requests to each of these URLs in parallel
...
1
vote
2answers
985 views
How to properly run multiple async tasks in parallel?
What if you need to run multiple asynchronous I/O tasks in parallel but need to make sure that no more than X I/O processes are running at the same time; and pre and post I/O processing tasks ...
6
votes
1answer
451 views
Dealing with a very large number of files
I am currently working on a research project which involves indexing a large number of files (240k); they are mostly html, xml, doc, xls, zip, rar, pdf, and text with filesizes ranging from a few KB ...
1
vote
1answer
190 views
Returning a BlockingCollection as IEnumerable from a method
I am trying to return an IEnumerable from a method that is backed by a BlockingCollection. The code pattern is:
public IEnumerable<T> Execute() {
var results = new ...
6
votes
3answers
3k views
When to use TaskEx.Run vs. TaskEx.RunEx
I'm trying to understand when to use TaskEx.Run. I have provided two code sample i wrote below that produce the same result. What i fail to see is why i would take the Task.RunEx TaskEx.RunEx ...
6
votes
2answers
327 views
Is this ok to derive from TPL Task to return more details from method?
My original method looks like:
string DoSomeWork();
Method DoSomeWork starts some work on other thread and returns execution ID (just random string). Later on I can query results by given execution ...
11
votes
2answers
265 views
Code Contracts and Asynchrony
What is the recommended way for adding postconditions to async methods which return Task<T>?
I have read the following suggestion:
...
2
votes
2answers
384 views
Explicitly specifying the TaskScheduler for an implicitly scheduled method
I have the following method which uses implicit scheduling:
private async Task FooAsync()
{
await Something();
DoAnotherThing();
await SomethingElse();
DoOneLastThing();
}
However, from ...
3
votes
0answers
271 views
CallContext - What are the recommendations for using this going forwards? [closed]
Does anyone know if there's any planned support in upcoming versions of .NET for storing objects in the ambient execution context? There's a definite need for it, as highlighted in the following ...
3
votes
1answer
155 views
Wrapping existing async method into TPL-compatiable method
How to wrap existing async method that accepts callback function as parameter into Task Parallel Library-compatible method?
// Existing method
void DoAsync(Action<string> callback) {
...
}
...
4
votes
1answer
414 views
Async CTP - Ambient CancellationToken and IProgress
Bearing in mind the Async CTP promotes implicit scheduling via an ambient SynchronizationContext, is there any reason why I should not make my CancellationToken and IProgress ambient too?
I'm ...
9
votes
1answer
1k views
Async CTP - Recommended approach for task scheduling
I'm currently working on a largely asynchronous application which uses TAP throughout. Every class which has methods for spawning Tasks also has a TaskScheduler injected into it. This allows us to ...
3
votes
2answers
1k views
TaskEx.Yield(TaskScheduler)
Last month I asked the following question which resulted in my learning of TaskEx.Yield:
Can async methods have expensive code before the first 'await'?
However, I have since realized that ...
7
votes
2answers
326 views
Can async methods have expensive code before the first 'await'?
Is it bad to have expensive code at the start of an async method, before the first await is called? Should this code be wrapped with a TaskEx.Run instead?
public async Task Foo()
{
// Do some ...
4
votes
2answers
450 views
EF4, TransactionScope and Task<>
Is it possible to open a TransactionScope, run a load of async Tasks which operate on an EF4 ObjectContext, and then commit the result?
How is the current transaction scope inferred in EF4? Will this ...
2
votes
1answer
385 views
Multiple Task<T> or IProgress<T> for partial completion?
I am using an asynchronous operation that completes in three steps, returning partial results before completion. Originally it's using events to signal progress, and I want to wrap it properly as an ...
32
votes
5answers
6k views
What's the difference between returning void and returning a Task?
In looking at various C# Async CTP samples I see some async functions that return void, and others that return the non-generic Task. I can see why returning a Task<MyType> is useful to return ...
3
votes
1answer
529 views
Async CTP Bug - Task Never Completes
Firstly a forward apology: I cannot isolate the following bug into a simple console application. However, in my relatively simple ASP.NET Web Forms application, the following code will cause the ...
6
votes
3answers
443 views
What is the best way to wait on a network packet using C#'s new async feature
I've recently been playing around with the new Async CTP, and I've come across a situation where I'm not sure how to proceed.
In my current code base, I'm using a concept of "jobs" and a "job ...
5
votes
3answers
1k views
Task chaining without TaskCompletionSource?
I'm converting some async/await code to chained tasks, so I can use it in the released framework. The await code looks like this
public async Task<TraumMessage> Get() {
var message = await ...
1
vote
2answers
753 views
Is there a way to use Task<T> as a waithandle for a future value T?
I'd like to use Task return from a method to return a the value when it becomes available at later time, so that the caller can either block using Wait or attach a continuation or even await it. The ...
4
votes
2answers
2k views
Task.Factory.StartNew() vs. TaskEx.Run()
Task.Factory.StartNew() basically receives an Action and returns a Task. In The Async CTP we have TaskEx.Run() which also receives an Action and returns a Task. They seem to do that same thing. Why ...
3
votes
4answers
440 views
How to create a parallel prefetch for a foreach
Give the numerous new ways of performing asynchronous operations in C#, TPL, Parallel Extensions, Async CTP, Reactive Extensions I was wonder what the simplest way to parallelize the fetching and ...
0
votes
1answer
185 views
Can I install the Async CTP without breaking anything?
I'd like to play with the Async CTP. Can I install it on my day-to-day workstation without breaking anything?
I've installed VS2010 SP1. I have ReSharper 5.1.x installed.