The Task Parallel Library is part of .NET 4 and .NET 4.5. It is a set of APIs to enable developers to program asynchronous applications.
6
votes
5answers
7k views
Best way in .NET to manage queue of tasks on a separate (single) thread
I know that asynchronous programming has seen a lot of changes over the years. I'm somewhat embarrassed that I let myself get this rusty at just 34 years old, but I'm counting on StackOverflow to ...
-3
votes
0answers
22 views
Can't update UI when main thread Sync context is system.threading.synchronizationContext
I have WPF application targeting .NET 4.5.2 and it uses the technique from Stephen Cleary's blog described in the post Task run and UI progress update that uses Task.Run and IProgress to update my UI, ...
-1
votes
2answers
58 views
Getting result from Task.Run
Hi guys i'm trying to get some results from Task.Run but i cannot figure it how
I have multiple methods that i would like to run in parallel and extract result:
This is one of the methods
protected ...
5
votes
0answers
174 views
Why does attempting to start a task cause an EntryPointNotFoundException?
In my application, I have a utility class which is supposed to execute a series of tasks in parallel, and provide reporting on the success and timing of the various tasks.
Every time I run it, I get ...
6
votes
1answer
2k views
What is the best way for wrapping synchronous code into asynchronous method
I am creating an application with using async-await methods. But There is a large problem for me with using them. After reading few articles I still don't know what is the best way for wrapping my ...
0
votes
3answers
53 views
How to catch an Exception that has been thrown in the ContinueWith part of a task?
On a button_click event, I start a Task to do some time consuming calculations asynchronously. I use Task.ContinueWith and set the TaskSheduler for the continuation to the UI synchronization context ...
2
votes
0answers
27 views
.NET queued tasks (with async/await)
I have a large number of tasks (~1000) that need to be executed. I am running on a 4-core processor, so I'd like to process 4 tasks at a time, in parallel.
To give you a starting point, here is some ...
0
votes
0answers
55 views
C# Split List<T> into groups using TPL Parallel ForEach
I need to process a List<T> of thousands of elements.
First I need to group the elements by year and type, so I obtain a List<List<T>>. Then for each internal List<T> I want ...
3
votes
1answer
758 views
Cancel task.delay without exception or use exception to controll flow?
I'm unsure about two possibilities to react to an event in my code. Mostly I'm concerned about which one needs less resources.
I have a method with an observer registered to an eventproducer. If the ...
64
votes
6answers
19k views
Should i use ThreadPools or Task Parallel Library for IO-bound operations
In one of my projects that's kinda an aggregator, I parse feeds, podcasts and so from the web.
If I use sequential approach, given that a large number of resources, it takes quite a time to process ...
4
votes
5answers
679 views
Accuracy of Task.Delay
I'm developing Windows 10 Universal App in C#/Xaml, I'm using await Task.Delay(delayInMilliseconds) to suspend a method for given time. My scenario is somewhat realtime, so it's very sensitive to time ...
16
votes
3answers
4k views
TaskScheduler.FromCurrentSynchronizationContext - how to use WPF dispatcher thread when unit testing
I've got code in a ViewModel that calls a service through a task.
When the task finishes, it'll populate an ObservableCollection.
The problem is that it's waiting on the task to finish by using the ...
2
votes
1answer
43 views
How to get the stack trace from own methods only when using TPL?
I want to get the names of the methods so called my function, It seems a bit of a problem with Tpl
Is there any good solution?
BTW: I aware of the CallerMemberName, But I want a different solution ...
17
votes
1answer
11k views
Parallel.Foreach exceptions and cancel
I have tried to find out how exceptions and cancel work for Parallel.Foreach. All examples seems to deal with Tasks.
What happens on an exception in Parallel.Foreach?
- Do I wrap the entire loop in ...
6
votes
2answers
2k views
Parallel.ForEach stalled when integrated with BlockingCollection
I adopted my implementation of parallel/consumer based on the code in this question
class ParallelConsumer<T> : IDisposable
{
private readonly int _maxParallel;
private readonly Action&...
3
votes
3answers
64 views
How to chain independent C# tasks?
Let's say I have two independent async functions (that I don't control) that create Task objects:
Task A();
Task B();
and some other non-async function
void X();
How do I construct a single Task ...
45
votes
6answers
12k views
Awaiting multiple Tasks with different results
I have 3 tasks:
private async Task<Cat> FeedCat() {}
private async Task<House> SellHouse() {}
private async Task<Tesla> BuyCar() {}
They all need to run before my code can continue ...
2
votes
4answers
292 views
How to mark a TPL dataflow cycle to complete?
Given the following setup in TPL dataflow.
var directory = new DirectoryInfo(@"C:\dev\kortforsyningen_dsm\tiles");
var dirBroadcast=new BroadcastBlock<DirectoryInfo>(dir=>dir);
var ...
58
votes
3answers
19k views
Simplest way to do a fire and forget method in c# 4.0
I really like this question:
Simplest way to do a fire and forget method in C#?
I just want to know that now that we have Parallel extensions in C# 4.0 is there a better cleaner way to do Fire & ...
157
votes
4answers
39k views
If my interface must return Task what is the best way to have a no-operation implementation?
In the code below, due to the interface, the class LazyBar must return a task from it's method (and for arguments sake can't be changed). If LazyBars implementation is unusual in that it happens to ...
22
votes
5answers
4k views
Use Task.Run() in synchronous method to avoid deadlock waiting on async method?
UPDATE The purpose of this question is to get a simple answer about Task.Run() and deadlocking. I very much understand the theoretical reasoning for not mixing async and sync, and I take them to ...
4
votes
1answer
85 views
Can this parallel async call be simplified?
I think async/await keywords here are redundant.
Parallel.Invoke(
async () => await DoSomethingAsync(1).ConfigureAwait(false),
async () => await DoSomethingAsync(2).ConfigureAwait(false)...
2
votes
1answer
36 views
PLINQ iteration of looping enumerator causes deadlock
I have a simple program that iterates over an endless enumerable implemented as a feedback enumerator. I have implemented this in both TPL and PLINQ. Both examples lockup after a predictable number of ...
10
votes
4answers
2k 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 ...
0
votes
1answer
28 views
Task deadlock doesn't occur
I found this example in the book. And it's written that this code leads to deadlock. But I don't get it and don't understand why it should be?
I always get
“Locked B and A”
“Locked A and B”
...
61
votes
6answers
30k views
Nesting await in Parallel.ForEach
In a metro app, I need to execute a number of WCF calls. There are a significant number of calls to be made, so I need to do them in a parallel loop. The problem is that the parallel loop exits ...
3
votes
3answers
60 views
C# Make Task Threads Forground
I am using Task to create and perform some operations by different thread, once operation is done i also has call back to be called.
System.Threading.Tasks.Task.Factory.StartNew(() =>
...
2
votes
1answer
29 views
MaxDegreeOfParallelism Not Applying to list of Tasks?
I have a list of tasks that I want to execute in parallel but in a limited fashion, almost like batching without me having to manage it. My approach was to use Parallel.ForEach and the ...
1
vote
4answers
6k views
How to pause task execution
I have this code that creates a task:
Task.Factory.StartNew(() =>
{
ExtractStuff(fileName);
});
Sometimes I need to ...
83
votes
4answers
72k views
Calling async method synchronously
I have an async method:
public async Task<string> GenerateCodeAsync()
{
string code = await GenerateCodeService.GenerateCodeAsync();
return code;
}
I need to call this method from a ...
7
votes
4answers
8k views
How to make two SQL queries really asynchronous
My problem is based on a real project problem, but I have never used the System.Threading.Tasks library or performing any serious programming involving threads so my question may be a mix of lacking ...
2
votes
2answers
58 views
Completion in TPL Dataflow Loops
I have a problem with determining how to detect completion within a looping TPL Dataflow.
I have a feedback loop in part of a dataflow which is making GET requests to a remote server and processing ...
-1
votes
0answers
42 views
.Net process cannot access a file, because it is being used by another process
I am downloading thousands of files By FTP using tamirssh dll library.
After downloading each .gz file I have to unzip it, process the contents and then push the data in to Oracle database, but the ...
1
vote
1answer
15 views
Task with Action Delegate accepting string parameter
I have just started with parallel programming. I want to create an action delegate method that print a message on console. When I chenge Action<string> to Action<object> and PritMessage ...
1
vote
1answer
48 views
Task.WhenAny throttling efficiency
I was recently reading through some documentation for using TAP, specifically this page under the smaller heading "Task.WhenAny." They state 4 primary purposes for the Task.WhenAny:
Redundancy
...
1
vote
2answers
71 views
How to avoid exception The process cannot access the file because it is being used by another process. in .net
I am unzipping a.gz files by using the following code.Since i have huge number of files , I am using TPL tasks to run this code. But I used to get .NET exception:
The process cannot access the file ...
3
votes
1answer
47 views
How to Fill Data Grid View without being my form stop responding?
I'm currently filling my DataGridView using Tasks. At first, when I fill in dataTable, everything is fine, but when I continue to the UI thread, my form is unresponsive for a short time.
How can I ...
0
votes
0answers
45 views
Can't step into an async method located in a release build [duplicate]
It looks like it isn't possible to step into an async method if it is located in a assembly build in release mode.
I have created very simple example for testing this.
var sleep = new Sleep();
...
1
vote
0answers
64 views
How do I abort a Task? [duplicate]
I have the following code
var ts = new CancellationTokenSource();
var ct = ts.Token;
object result;
if (Task.Factory.StartNew(() =>
{
result = ...
3
votes
3answers
69 views
Notify task when other tasks complete
.Net TPL experts,
Note: Cannot use DataFlow library; no add-ons allowed.
I have four tasks as shown in the diagram below:
task_1 (data_producer) -> reads records from a large file (>500000 records) ...
1
vote
1answer
62 views
RX + TPL + Testing
I currently struggling with the issue testing a TPL function inside of a `RX statement. The problem is also that I don't have access to the observable.
Here is my test:
[Test]
public void ...
2
votes
3answers
37 views
Awaited task ended in Canceled state does not throw
Reading Task-based Asynchronous Pattern by Stephen Toub I'm trying to see how cancellation works for tasks.
In the section Consuming the Task-based Asynchronous Pattern under Await, in 3-rd paragraph ...
8
votes
3answers
2k views
A code example illustrating the difference between the paradigms of async/await and Reactive (Rx) extension?
Both the System.Reactive extension for .NET and new C# 5.0 (.NET 4.5) async/await pursue (or based on) future and promises constructs paradigm (approach).
Can you give the (*) simplest C# code ...
2
votes
0answers
53 views
parallel/asynchrone load heavy ui wpf
I have some issue loading my app, it takes too much time. So i want to optimize the code using .net 4.5. I already replace my code with async/await pattern for WCF calls, I/O operations and some ...
0
votes
1answer
36 views
Large Data Initial Setup Pattern for Task Parallel Library
For those of you looking to parallelize your compute-intensive algorithms, let me point you to this document on common patterns leveraging the Task Parallel Library of .NET 4 and beyond: https://www....
2
votes
2answers
45 views
How to store results from tasks running in threadpool?
I have a problem with a threadpool efficiency. I'm not sure I understand the whole concept. I did a lot of reading before asking that question and I know that threadpool is a good solution if you have ...
0
votes
1answer
31 views
Task.Factory.StartNew not executing the method in .net [closed]
I have around 5000 files located in FTP, so i am downloading those by using FTP and then unzipping the files, finally processing and pushing in to oracle database.Except processing and pushing in to ...
2
votes
1answer
55 views
Using Reactive Extensions can I create subscribers to an observable which block until some condition is met or a timeout occurs
Can I/Should I use reactive extensions for this?
Basically I have an ESB which I want to monitor for messages (which is essentially where my hot observable sits atop) , and I want to create a bunch of ...
2
votes
2answers
512 views
Parallel.ForEach Set MaxDegreeOfParallelism globally
Say I have a situation where I really want to use Parallel.ForEach instead of a regular foreach loop because it's much more performant (and way cooler), but having .NET determine the degree of ...
150
votes
3answers
28k views
WaitAll vs WhenAll
What is the difference between Task.WaitAll() and TaskEx.WhenAll() from the Async CTP ?
Can you provide some sample code to illustrate the different use cases ?