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
486
votes
13 answers

How to safely call an async method in C# without await

I have an async method which returns no data: public async Task MyAsyncMethod() { // do some stuff async, don't return any data } I'm calling this from another method which returns some data: public string GetStringData() { MyAsyncMethod();…
George Powell
  • 9,141
  • 8
  • 35
  • 43
431
votes
3 answers

Task vs Thread differences

There are two classes available in .NET: Task and Thread. What is the difference between those classes? When is it better to use Thread over Task (and vice-versa)?
Jacek
  • 11,661
  • 23
  • 69
  • 123
426
votes
2 answers

When correctly use Task.Run and when just async-await

I would like to ask you on your opinion about the correct architecture when to use Task.Run. I am experiencing laggy UI in our WPF .NET 4.5 application (with Caliburn Micro framework). Basically I am doing (very simplified code snippets): public…
Lukas K
  • 6,037
  • 4
  • 23
  • 31
387
votes
12 answers

Awaiting multiple Tasks with different results

I have 3 tasks: private async Task FeedCat() {} private async Task SellHouse() {} private async Task BuyCar() {} They all need to run before my code can continue and I need the results from each as well. None of the results have…
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
365
votes
9 answers

Why use async and return await, when you can return Task directly?

Is there any scenario where writing method like this: public async Task DoSomethingAsync() { // Some synchronous code might or might not be here... // return await DoAnotherThingAsync(); } instead of this: public…
TX_
  • 5,056
  • 3
  • 28
  • 40
252
votes
6 answers

Do rails rake tasks provide access to ActiveRecord models?

I am trying to create a custom rake task, but it seems I dont have access to my models. I thought this was something implicitly included with rails task. I have the following code in lib/tasks/test.rake: namespace :test do task :new_task do …
gmoniey
  • 7,975
  • 4
  • 27
  • 30
249
votes
7 answers

What is the use for Task.FromResult in C#

In C# and TPL (Task Parallel Library), the Task class represents an ongoing work that produces a value of type T. I'd like to know what is the need for the Task.FromResult method ? That is: In a scenario where you already have the produced value at…
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
239
votes
12 answers

Deleting all pending tasks in celery / rabbitmq

How can I delete all pending tasks without knowing the task_id for each task?
nabizan
  • 3,185
  • 5
  • 26
  • 38
236
votes
5 answers

Task continuation on UI thread

Is there a 'standard' way to specify that a task continuation should run on the thread from which the initial task was created? Currently I have the code below - it is working but keeping track of the dispatcher and creating a second Action seems…
Greg Sansom
  • 20,442
  • 6
  • 58
  • 76
233
votes
4 answers

Parallel.ForEach vs Task.Run and Task.WhenAll

What are the differences between using Parallel.ForEach or Task.Run() to start a set of tasks asynchronously? Version 1: List strings = new List { "s1", "s2", "s3" }; Parallel.ForEach(strings, s => { DoSomething(s); }); Version…
Petter T
  • 3,387
  • 2
  • 19
  • 31
164
votes
13 answers

How do I abort/cancel TPL Tasks?

In a thread, I create some System.Threading.Task and start each task. When I do a .Abort() to kill the thread, the tasks are not aborted. How can I transmit the .Abort() to my tasks ?
Patrice Pezillier
  • 4,476
  • 9
  • 40
  • 50
157
votes
6 answers

'await' works, but calling task.Result hangs/deadlocks

I have the following four tests and the last one hangs when I run it. Why does this happen: [Test] public void CheckOnceResultTest() { Assert.IsTrue(CheckStatus().Result); } [Test] public async void CheckOnceAwaitTest() { …
Johan Larsson
  • 17,112
  • 9
  • 74
  • 88
155
votes
16 answers

Run PHP Task Asynchronously

I work on a somewhat large web application, and the backend is mostly in PHP. There are several places in the code where I need to complete some task, but I don't want to make the user wait for the result. For example, when creating a new account, I…
davr
  • 18,877
  • 17
  • 76
  • 99
155
votes
2 answers

Difference between await and ContinueWith

Can someone explain if await and ContinueWith are synonymous or not in the following example. I'm trying to use TPL for the first time and have been reading all the documentation, but don't understand the difference. Await: String webText = await…
Harrison
  • 3,843
  • 7
  • 22
  • 49
153
votes
6 answers

Should I worry about "This async method lacks 'await' operators and will run synchronously" warning

I have a interface which exposes some async methods. More specifically it has methods defined which return either Task or Task. I am using the async/await keywords. I am in the process of implementing this interface. However, in some of these…
dannykay1710
  • 1,953
  • 2
  • 11
  • 13
1
2 3
99 100