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
131
votes
2 answers

Await on a completed task same as task.Result?

I'm currently reading "Concurrency in C# Cookbook" by Stephen Cleary, and I noticed the following technique: var completedTask = await Task.WhenAny(downloadTask, timeoutTask); if (completedTask == timeoutTask) return null; return await…
julio.g
  • 3,268
  • 5
  • 28
  • 25
124
votes
9 answers

How can I call an async method in Main?

public class test { public async Task Go() { await PrintAnswerToLife(); Console.WriteLine("done"); } public async Task PrintAnswerToLife() { int answer = await GetAnswerToLife(); …
Larry
  • 2,172
  • 2
  • 14
  • 20
121
votes
5 answers

How do I enable TODO/FIXME/XXX task tags in Eclipse?

In all my years of using Eclipse, I never knew until now that TODO / FIXME / XXX comment tags are supposed to appear in the task list. Apparently this is something that is disabled by default because I have been using those tags for as long as I've…
Jeff
  • 1,511
  • 2
  • 14
  • 12
115
votes
2 answers

Await vs Task.Result in an Async Method

What's the difference between doing the following: async Task method(){ var r = await dynamodb.GetItemAsync(...) return r.Item; } vs async Task method(){ var task = dynamodb.GetItemAsync(...) return task.Result.Item; } In my…
luis
  • 2,067
  • 2
  • 13
  • 21
112
votes
8 answers

Task.Run with Parameter(s)?

I have implemented a simple Task.Factory.StartNew() and I wonder how can I do it with Task.Run() instead? Here is the basic code: Task.Factory.StartNew(new Action( (x) => { // Do something with 'x' }), rawData); I looked into…
Thus Spoke Nomad
  • 2,372
  • 4
  • 17
  • 34
110
votes
2 answers

A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was

What does this mean and how to resolve it? I am using TPL tasks. The whole error A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the…
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
107
votes
7 answers

Timer & TimerTask versus Thread + sleep in Java

I found similar questions asked here but there weren't answers to my satisfaction. So rephrasing the question again- I have a task that needs to be done on a periodic basis (say 1 minute intervals). What is advantage of using Timertask & Timer to do…
Keshav
  • 4,408
  • 8
  • 31
  • 50
107
votes
1 answer

Difference between OperationCanceledException and TaskCanceledException?

What is the difference between OperationCanceledException and TaskCanceledException? If I am using .NET 4.5 and using the async/await keywords, which one should I be looking to catch?
Peter
  • 1,685
  • 3
  • 16
  • 22
103
votes
4 answers

Platform.runLater and Task in JavaFX

I have been doing some research on this but I am still VERY confused to say the least. Can anyone give me a concrete example of when to use Task and when to use Platform.runLater(Runnable);? What exactly is the difference? Is there a golden rule to…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
101
votes
6 answers

Promise equivalent in C#

In Scala there is a Promise class that could be used to complete a Future manually. I am looking for an alternative in C#. I am writing a test and I want it to look it similar to this: // var MyResult has a field `Header` var promise = new…
eddyP23
  • 6,420
  • 7
  • 49
  • 87
94
votes
3 answers

How to properly create and run concurrent tasks using python's asyncio module?

I am trying to properly understand and implement two concurrently running Task objects using Python 3's relatively new asyncio module. In a nutshell, asyncio seems designed to handle asynchronous processes and concurrent Task execution over an event…
songololo
  • 4,724
  • 5
  • 35
  • 49
93
votes
12 answers

My C# application is returning 0xE0434352 to Windows Task Scheduler but it is not crashing

I have written a few C# apps that I have running via windows task scheduler. They are running successfully (as I can see from the log files that they are writing ) but windows task scheduler shows them returning a last run result of 0xE0434352. Is…
Kynrek
  • 1,319
  • 1
  • 10
  • 9
89
votes
4 answers

Why is Task not co-variant?

class ResultBase {} class Result : ResultBase {} Task GetResult() { return Task.FromResult(new Result()); } The compiler tells me that it cannot implicitly convert Task to Task. Can someone explain why this is?…
chosenbreed37
  • 1,292
  • 9
  • 10
88
votes
7 answers

What is the best way to seed a database in Rails?

I have a rake task that populates some initial data in my rails app. For example, countries, states, mobile carriers, etc. The way I have it set up now, is I have a bunch of create statements in files in /db/fixtures and a rake task that processes…
Tony
  • 18,776
  • 31
  • 129
  • 193
88
votes
8 answers

What is the 'realtime' process priority setting for?

From what I've read in the past, you're encouraged not to change the priority of your Windows applications programmatically, and if you do, you should never change them to 'Realtime'. What does the 'Realtime' process priority setting do, compared to…
Chris S
  • 64,770
  • 52
  • 221
  • 239