Questions tagged [task]

A task is an abstraction that is used to work with concurrency, it can denote operation that should be executed concurrently with the rest of a program. A task is a concurrent thread of execution in Ada and represents an asynchronous operation in .NET, also it corresponds to Threads in Java.

A task is an abstraction that is used to work with concurrency, it can denote operation that should be executed concurrently with the rest of a program.

  • Ada
    A task is a concurrent thread of execution in an Ada program. Task definitions are split into two parts - declaration and a body, which is mandatory. Task declaration defines entities exported from the task, whereas its body contains local declarations and statements of the task.

  • .NET
    Task is used to represents an asynchronous operation, it is a core concept of the which is used for asynchronous and parallel programming in the .NET framework.

  • C++
    future is used to represent an operation which may complete some time in the future. It helps programs achieve a degree of asynchrony where they may want/need to perform certain operations in parallel. std::async creates a task which may execute asynchronously, returning a std::future.

See also:

Related tags

8481 questions
43
votes
8 answers

System.Threading.Tasks - Limit the number of concurrent Tasks

I have just started to look at the new "System.Threading.Tasks" goodness in .Net 4.0, and would like to know if there is any build in support for limiting the number of concurrent tasks that run at once, or if this should be manually handled. E.G:…
James
  • 7,877
  • 7
  • 42
  • 57
41
votes
1 answer

Waiting on a Task with a OnlyOnFaulted Continuation causes an AggregateException

I have some simple code as a repro: var taskTest = Task.Factory.StartNew(() => { System.Threading.Thread.Sleep(5000); }).ContinueWith((Task t) => { Console.WriteLine("ERR"); }, TaskContinuationOptions.OnlyOnFaulted); try { …
Redth
  • 5,464
  • 6
  • 34
  • 54
41
votes
3 answers

await Task.CompletedTask for what?

I created UWP app with Windows Template Studio that introduced at Build2017. Below class is a part of generated code from it. public class SampleModelService { public async Task> GetDataAsync() { await…
Youngjae
  • 24,352
  • 18
  • 113
  • 198
40
votes
1 answer

When does a C# Task actually start?

When does a Task actually start? public void DoSomething() { Task myTask = DoSomethingAsync(); Task.WaitAll(new[] { myTask }, 2000); } public async Task DoSomethingAsync() { await SomethingElse(); } Does it start immediately when…
TheHvidsten
  • 4,028
  • 3
  • 29
  • 62
40
votes
2 answers

Why is Rake not able to invoke multiple tasks consecutively?

I have a Rake task which I have simplified below. I'm using Ruby 1.9 on Windows. Perhaps you would like to guess the outcome of calling the Rake task "list_all_levels" below? It should be: "Hello level 1" "Hello level 2" "Hello level 3" But for…
PandaWood
  • 8,086
  • 9
  • 49
  • 54
40
votes
3 answers

CancellationToken UnRegister Action

I have a token for various tasks and I need to better manage their cancellation, to be notified of a cancellation I can use: token.Register(RegisterMethod); How can I remove this "subscription"? Is there any way to "UnRegister"? I thought about…
J. Lennon
  • 3,311
  • 4
  • 33
  • 64
39
votes
1 answer

Would a Task.Convert extension method be useful or does it have hidden dangers?

I'm writing client libraries for Google Cloud APIs which have a fairly common pattern for async helper overloads: Do some brief synchronous work to set up a request Make an asynchronous request Transform the result in a simple way Currently we're…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
39
votes
2 answers

what does gulp-"cli" stands for?

Can someone please explain what exactly are the differences between the following two methods of gulp installation: $ npm install --global gulp-cli and $ sudo npm install -g gulp It looks to me that both do the same thing except that the first…
York Wang
  • 1,909
  • 5
  • 15
  • 27
38
votes
1 answer

How do task killers work?

The usefullness of task killer apps is debated, but I'm wondering: how do they actually work? How is it possible to kill particular process? Is there an API for this, and if so what does it actually do? EDIT Worth adding: I saw task killer apps…
user468311
38
votes
1 answer

What does "long-running tasks" mean?

By default, the CLR runs tasks on pooled threads, which is ideal for short-running compute-bound work. For longer-running and blocking operations, you can prevent use of a pooled thread as follows: Task task = Task.Factory.StartNew (() =>…
Person.Junkie
  • 1,816
  • 4
  • 21
  • 31
36
votes
5 answers

Does Task.Wait(int) stop the task if the timeout elapses without the task finishing?

I have a task and I expect it to take under a second to run but if it takes longer than a few seconds I want to cancel the task. For example: Task t = new Task(() => { while (true) { …
Paul Mendoza
  • 5,709
  • 12
  • 53
  • 82
36
votes
5 answers

NSubstitute - mock throwing an exception in method returning Task

Using NSubstitute, how do you mock an exception being thrown in a method returning a Task? Let's say our method signature looks something like this: Task> GetAllAsync(); Here's how NSubstitute docs say to mock throwing exceptions for…
Brandon
  • 1,566
  • 2
  • 14
  • 22
36
votes
5 answers

AfterPublish target not working

World's simplest task (see below) is not being executed after I publish my web application project. Any idea why?
Mark
  • 361
  • 1
  • 3
  • 4
35
votes
3 answers

Should we use ConfigureAwait(false) in libraries that call async callbacks?

There are lots of guidelines for when to use ConfigureAwait(false), when using await/async in C#. It seems the general recommendation is to use ConfigureAwait(false) in library code, as it rarely depends on the synchronization context. However,…
35
votes
2 answers

Task.WaitAll method vs Parallel.Invoke method

I have sample code to compare processing time for Parallel approach and Task approach. The goal of this experiment is understanding of how do they work. So my questions are: Why Parallel worked faster then Task? Do my results mean that I should use…
Igor Lozovsky
  • 2,275
  • 2
  • 15
  • 14