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
28
votes
6 answers

Is it better to return an empty task or null? c#

I have an asynchronous method which will look for a jobId for a job scheduling service through an Api. if it finds no results is it better to return an empty task or null? As i understand when returning a collection it is better to return an empty…
crayoyeah
  • 283
  • 1
  • 3
  • 8
28
votes
3 answers

Running tasks parallel in powershell

I have a PowerShell script like this: Foreach ($file in $files) { [Do something] [Do something] [Do something] } This way one file is treated after the other. I want to treat 4 files at the same time. I know of the foreach -parallel…
Werner Schoemaker
  • 455
  • 1
  • 6
  • 11
28
votes
2 answers

Parallel execution for IO bound operations

I have read TPL and Task library documents cover to cover. But, I still couldn't comprehend the following case very clearly and right now I need to implement it. I will simplify my situation. I have an IEnumerable of length 1000. I have to…
ozgur
  • 2,549
  • 4
  • 25
  • 40
28
votes
1 answer

Spring ThreadPoolTaskScheduler vs ThreadPoolTaskExecutor

It is mentioned in the Spring documentation that: ThreadPoolTaskScheduler actually implements Spring's TaskExecutor interface as well, so that a single instance can be used for asynchronous execution as soon as possible as well as scheduled, and…
chammu
  • 1,275
  • 1
  • 18
  • 26
28
votes
3 answers

How to convert a Task to a Task?

Since C#'s Task is a class, you obviously can't cast a Task to a Task. However, you can do: public async Task Run() { return await MethodThatReturnsDerivedTask(); } Is there a static task method I can call to get a…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
27
votes
1 answer

Why is the call ambiguous? 'Task.Run(Action)' and 'Task.Run(Func)'

Considering the following code: public void CacheData() { Task.Run((Action)CacheExternalData); Task.Run(() => CacheExternalData()); Task.Run(CacheExternalDataTask); Task.Run(CacheExternalData); } public Task…
Tom Bowen
  • 8,214
  • 4
  • 22
  • 42
27
votes
4 answers

Understanding async / await and Task.Run()

I thought I understood async/await and Task.Run() quite well until I came upon this issue: I'm programming a Xamarin.Android app using a RecyclerView with a ViewAdapter. In my OnBindViewHolder Method, I tried to async load some images public…
Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59
27
votes
4 answers

Can I use Task.Delay as a timer?

I want to execute some code on each second. The code I am using now is: Task.Run((Action)ExecuteSomething); And ExecuteSomething() is defined as below: private void ExecuteSomething() { Task.Delay(1000).ContinueWith( …
Sharun
  • 3,022
  • 6
  • 30
  • 59
27
votes
2 answers

asyncio and coroutines vs task queues

I've been reading about asyncio module in python 3, and more broadly about coroutines in python, and I can't get what makes asyncio such a great tool. I have the feeling that all you can do with coroutines, you can do better by using task queues…
MG1992
  • 537
  • 1
  • 8
  • 16
27
votes
2 answers

Having multiple main functions on Go

As a Python and Django developer, I can run any piece of code in my project using a script independently. I am not too sure how to achieve the same thing in Go, as it looks like each Go project should only have one main executable file. I'd like to…
mohi666
  • 6,842
  • 9
  • 45
  • 51
27
votes
4 answers

Polling the right way?

I am a software/hardware engineer with quite some experience in C and embedded technologies. Currently i am busy with writing some applications in C# (.NET) that is using hardware for data acquisition. Now the following, for me burning,…
Velocity
  • 375
  • 1
  • 3
  • 8
26
votes
6 answers

Why *not* change the priority of a ThreadPool (or Task) thread?

There are many places across the web and Stack Overflow where one is discouraged from changing the priority of a ThreadPool thread or TPL Task. In particular: "You have no control over the state and priority of a thread pool thread." "The runtime…
Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108
26
votes
2 answers

How do Google App Engine Task Queues work?

I'm confused about Task execution using queues. I've read the documentation and I thought I understood bucket_size and rate, but when I send 20 Tasks to a queue set to 5/h, size 5, all 20 Tasks execute one after the other as quickly as possible,…
Will Curran
  • 6,959
  • 15
  • 59
  • 92
26
votes
2 answers

Why so many tasks in my spark job? Getting 200 Tasks By Default

I have a spark job that takes a file with 8 records from hdfs, does a simple aggregation and saves it back to hdfs. I notice there are like hundreds of tasks when I do this. I also am not sure why there are multiple jobs for this? I thought a…
uh_big_mike_boi
  • 3,350
  • 4
  • 33
  • 64
26
votes
3 answers

is using an an `async` lambda with `Task.Run()` redundant?

I just came across some code like: var task = Task.Run(async () => { await Foo.StartAsync(); }); task.Wait(); (No, I don't know the inner-workings of Foo.StartAsync()). My initial reaction would be get rid of async/await and rewrite as: var task…
Ðаn
  • 10,934
  • 11
  • 59
  • 95