Questions tagged [taskfactory]

TaskFactory is used to create and schedule Task objects in the .Net framework.

TaskFactory is used to create and schedule Task objects in the .Net framework.

References

81 questions
48
votes
4 answers

lowering priority of Task.Factory.StartNew thread

a code like below will start a new thread to do the job. Is there any way I can control the priority of that thread? Task.Factory.StartNew(() => { // everything here will be executed in a new thread. // I want to set the priority of this…
Moon
  • 33,439
  • 20
  • 81
  • 132
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
20
votes
2 answers

TPL TaskFactory.FromAsync vs Tasks with blocking methods

I was wondering if there were any performance implications between using TPL TaskFactory.FromAsync and using TaskFactory.StartNew on blocking versions of the methods. I'm writing a TCP server that will support no more than 100 concurrent…
13
votes
3 answers

Different exception handling between Task.Run and Task.Factory.StartNew

I encountered an issue when I was using Task.Factory.StartNew and tried to capture an exception that is thrown. In my application I have a long running task that I want to encapsulate in a Task.Factory.StartNew(.., TaskCreationOptions.LongRunning);…
default
  • 11,485
  • 9
  • 66
  • 102
10
votes
3 answers

Sleep task (System.Threading.Tasks)

I need to create thread which will replace photo in Windows Forms window, than waits for ~1second and restore the previous photo. I thought that the following code: TaskScheduler ui = TaskScheduler.FromCurrentSynchronizationContext(); var task =…
patryk.beza
  • 4,876
  • 5
  • 37
  • 56
7
votes
2 answers

Create a Task with an Action multiple parameters

I want to add multiple parameter in a Task containing Action. I reviewed the existing stack-overflow question Create a Task with an Action Kindly assist me how to pass multiple arguments in a Action method in a Task Action action =…
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
5
votes
2 answers

how add tasks priority functionality

i use Task Library for my image compression service. I would to compress many files concurrency. But i want the service run only when user is idle(or no more impotarnt task in programm). I know that threadPool does not support "change thread…
4
votes
1 answer

Why does TaskFactory.StartNew in combination with Task.ContinueWith work?

TaskFactory.StartNew() creates a new Task, starts it and then returns it. I suppose that it is safe to assume that the following code will always work (since it was taken from MSDN): Task.Factory.StartNew(() => Console.WriteLine("first")) …
bitbonk
  • 48,890
  • 37
  • 186
  • 278
4
votes
1 answer

How to create a Task with TaskFactory.FromAsync and custom Async procedures

I am trying to test some classes that rely on a Task to do some background computation (retrieve data from a network location). The class gets a non-started instance of a Task, adds a ContinueWith method and then calls Start on the Task. Something…
Giraffe
  • 1,993
  • 3
  • 20
  • 20
4
votes
2 answers

How to ensure that Task.Factory.StartNew doesn't slow down the main thread?

There's a bunch of compressed data chunks that has to be asynchronously deflated - without blocking or slowing down the main thread in any shape or form. Decompressed chunks will be used by the main thread as soon as they are…
JBeurer
  • 1,707
  • 3
  • 19
  • 38
4
votes
2 answers

Disadvantages to Web Api methods returning Tasks

Why is the practice of returning a Task from Web Api methods not the default and in the methods that you get when you create a new Web Api Controller in Visual Studio? Are there any disadvantages to doing this? public class MyController :…
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
3
votes
3 answers

Task.Factory.StartNew "action" argument and higher level local variables

Consider this: void StartUpdate(DataRequest dataRequest) { Task.Factory.StartNew(request => {... do something with "request" ...}, dataRequest); } Now, my question: can I use dataRequest inside the lambda expression, instead of passing…
Andrey
  • 20,487
  • 26
  • 108
  • 176
3
votes
2 answers

Alternative of Thread.Abort for a cpu+time intensive method

i have a question about multithreading applications. I use the TaskFactory to start a cpu+time intensive method. This method is a call to SAP and needs a long time to finish. The user should have an option to cancel the task. Currently i am using…
MarcelD
  • 43
  • 4
3
votes
2 answers

How to start tasks after cancelling

I have a Windows form with three buttons. One button adds entries to a BlockingCollection. One starts processing the list and one stops processing the list. I can add entries to my BlockingCollection and when I click Start, the list is consumed as I…
Simon
  • 8,981
  • 2
  • 26
  • 32
2
votes
2 answers

parallel.for or task.startnew in multithreading process

I have a list of strings that I need to pass to a process in a different class. What I want to know which of the two ideas would be a better approach to use in terms of speed, efficiency and parallel processing. The list contains +- 10000 strings…
vbNewbie
  • 3,291
  • 15
  • 71
  • 155
1
2 3 4 5 6