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
25
votes
5 answers

How to return to the latest launched activity when re-launching application after pressing HOME?

Familiar scenario: I have a Main activity that launches a Game activity when a button is pressed. If the user presses HOME, and then launches my application again, it should be presented with the Game activity, which is what he was doing last when…
sole
  • 2,057
  • 2
  • 17
  • 18
25
votes
1 answer

C# Fire and Forget Task and discard

I need to do a fire and forget call to some async method. I realised VS is suggesting that I can set the call to a _discard and the IDE warning goes away. But I'm not sure if that call is still not awaited when used with the discard. Would it be? …
Selim Balci
  • 940
  • 2
  • 11
  • 26
25
votes
1 answer

How can I pass named arguments to a Rake task?

Is there a way to pass named arguments to a Rake task without using environment variables? I am aware that Rake tasks can accept arguments in two formats: Environment Variables $ rake my_task foo=bar This creates an environment variable with the…
Andrew
  • 1,590
  • 4
  • 19
  • 25
25
votes
3 answers

Creating a task wrapper around an existing object

I have a method which returns a Task where the implementation may or may not need to perform a slow operation in order to retrieve the result. I would like to be able to simply wrap the result value into a Task which is marked as having completed…
Star
  • 283
  • 1
  • 4
  • 5
25
votes
2 answers

Method that returns Task

I need a method that returns a Task with empty string like public static Task AsyncTest() { return new Task(() => string.Empty); //problem here // this method would work: // return new…
c0rd
  • 1,329
  • 1
  • 13
  • 20
25
votes
3 answers

TaskFactory.StartNew versus ThreadPool.QueueUserWorkItem

Apparently the TaskFactory.StartNew method in .NET 4.0 is intended as a replacement for ThreadPool.QueueUserWorkItem (according to this post, anyway). My question is simple: does anyone know why? Does TaskFactory.StartNew have better performance?…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
25
votes
1 answer

How many tasks are too many?

I'm currently working on an application that relies on many different web services to get data. Since I want to modularize each service and have a bit of dependency in there (service1 must run before service 2 and 3 etc), I'm running each service in…
Scurals
  • 253
  • 1
  • 3
  • 4
24
votes
3 answers

Does Task.WhenAll wait for all the tasks in case of exceptions

I have two tasks. I run both of them with Task.WhenAll. What happens if one of them throws an exception? Would the other one complete?
Jonatan Dragon
  • 4,675
  • 3
  • 30
  • 38
24
votes
3 answers

Start app at a specific time

I was wondering if it's possible (and if it is how) to start up my app at a specific time, something like an alarmclock which goes off at a specific time. Let's say I want my app to start up at 8 in the morning, is that feasable ?
TiGer
  • 5,879
  • 6
  • 35
  • 36
24
votes
4 answers

How can I measure the execution time of a npm/yarn task/script?

How can I measure the execution time of a npm/yarn task on the command line without modifying the scripts. In my special use case I want to execute an existing E2E-Test (yarn test:e2e) 100 times and take the average value.
user3025289
24
votes
2 answers

The return type of an async method must be void, Task or Task

I have the following code here: public async Dictionary GetLikelihoodsAsync(List inputs) { HttpClient client = new HttpClient(); string uri = GetUri(); string body = GetRequestBody(inputs); byte[]…
Tamas Ionut
  • 4,240
  • 5
  • 36
  • 59
24
votes
1 answer

CancellationTokenSource vs. volatile boolean

Are there any benefits for using a CancellationTokenSource over a volatile boolean field for signalling a Task to finish?
Yoav
  • 3,326
  • 3
  • 32
  • 73
24
votes
1 answer

Is catching TaskCanceledException and checking Task.Canceled a good idea?

There are some people on my team who really love coding with async Task. And sometimes they like to use CancellationToken parameters. What I'm unsure about is whether we should as a team be using this style of code (A): async Task
Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
24
votes
2 answers

Difference between Task and async Task

C# provides two ways of creating asynchronous methods: Task(): static Task MyAsyncTPL() { Task result = PerformWork(); return result.ContinueWith(t => MyContinuation()); } async Task(): static async Task MyAsync() { …
Chander Shivdasani
  • 9,878
  • 20
  • 76
  • 107
24
votes
2 answers

How to get files and directories name using Gradle?

I have dir in which another task create files and directories so in this dir there are files, directories, subdirectroies, files in them and ect. I want to put all absolute path of files and directories in a list. def listNames =…
Xelian
  • 16,680
  • 25
  • 99
  • 152