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
87
votes
7 answers

How to handle Task.Run Exception

I had a problem with catching the exception from Task.Run which was resolved by changing the code as follows. I'd like to know the difference between handling exceptions in these two ways : In the Outside method I can't catch the exception, but in…
Mohammad Chamanpara
  • 2,049
  • 1
  • 15
  • 23
86
votes
6 answers

How can I prevent synchronous continuations on a Task?

I have some library (socket networking) code that provides a Task-based API for pending responses to requests, based on TaskCompletionSource. However, there's an annoyance in the TPL in that it seems to be impossible to prevent synchronous…
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
84
votes
3 answers

How do I add a high-priority TODO comment in Visual Studio?

Adding a comment such as this: // TODO: Refactor this code ...creates a task in the Task List that I can view etc. There is a column labeled ! that lets you sort these tasks by priority. How can I set a specific task's priority?
aarona
  • 35,986
  • 41
  • 138
  • 186
83
votes
4 answers

When to use TaskCreationOptions.LongRunning?

I've wondered this for quite a while, but never really found the answer. I understand that it's a hint for the task scheduler where the task will run on, and that the task scheduler can (or nowadays will?) decide to instantiate a non-thread-pool…
bas
  • 13,550
  • 20
  • 69
  • 146
81
votes
1 answer

await Task.Delay() vs. Task.Delay().Wait()

In C# I have the following two simple examples: [Test] public void TestWait() { var t = Task.Factory.StartNew(() => { Console.WriteLine("Start"); Task.Delay(5000).Wait(); Console.WriteLine("Done"); }); …
svenskmand
  • 813
  • 1
  • 6
  • 5
78
votes
4 answers

Is Task.Factory.StartNew() guaranteed to use another thread than the calling thread?

I am starting a new task from a function but I would not want it to run on the same thread. I don't care which thread it runs on as long as it is a different one (so the information given in this question does not help). Am I guaranteed that the…
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
71
votes
7 answers

C# - ThreadPool vs Tasks

As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool. Which one is more efficient and less resource…
TheAJ
  • 10,485
  • 11
  • 38
  • 57
70
votes
12 answers

Asynchronous Task.WhenAll with timeout

Is there a way in the new async dotnet 4.5 library to set a timeout on the Task.WhenAll method? I want to fetch several sources, and stop after say 5 seconds, and skip the sources that weren't finished.
broersa
  • 1,656
  • 3
  • 16
  • 31
70
votes
6 answers

Proper way of handling exception in task continuewith

Please have a look at the following code- static void Main(string[] args) { // Get the task. var task = Task.Factory.StartNew(() => { return div(32, 0); }); // For error handling. task.ContinueWith(t => {…
Anirban Paul
  • 1,065
  • 1
  • 16
  • 22
67
votes
6 answers

What is the difference between a thread/process/task?

What is the difference between a thread/process/task?
billu
  • 2,415
  • 3
  • 23
  • 31
66
votes
6 answers

How do I wait until Task is finished in C#?

I want to send a request to a server and process the returned value: private static string Send(int id) { Task responseTask = client.GetAsync("aaaaa"); string result = string.Empty; responseTask.ContinueWith(x =>…
user266003
63
votes
9 answers

Android: Cancel Async Task

I use an async task to upload an image and get some results. While uploading the image I see a progress dialog, written in onPreExecute() method like this: protected void onPreExecute() { uploadingDialog = new…
steliosf
  • 3,669
  • 2
  • 31
  • 45
63
votes
2 answers

Thread.Sleep vs Task.Delay?

I know that Thread.Sleep blocks a thread. But does Task.Delay also block? Or is it just like Timer which uses one thread for all callbacks (when not overlapping)? (this question doesn't cover the differences)
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
61
votes
4 answers

Celery task that runs more tasks

I am using celerybeat to kick off a primary task that kicks of a number of secondary tasks. I have both tasks written already. Is there a way to easily do this? Does Celery allow for tasks to be run from within tasks? My example: @task def…
Mantas Vidutis
  • 16,376
  • 20
  • 76
  • 92
61
votes
3 answers

What is the point of .NET 4.6's Task.CompletedTask?

This blog post mentions the new Task APIs, including a new Task.CompletedTask property introduced in .NET 4.6. Why was this added? How is this better than, say, Task.FromResult(whatever)?
Gigi
  • 28,163
  • 29
  • 106
  • 188