4

My Task have to work for a long time (it's like a service) - so I need to make it LongRunning.

At the same time, I need to mark it as AttachedToParent to prevent parent task completion before my service's task completion.

How to combine this two task creation options?

astef
  • 8,575
  • 4
  • 56
  • 95
  • [Link to msdn](http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskcreationoptions.aspx) What is the problem?? – AAlferez May 23 '13 at 13:20
  • @AnnArbor87 I feel that "bitwise combination" is what I need. But unfortunately I've never used it – astef May 23 '13 at 13:23
  • So how are u creating the task? as a child from the parent? or just creating it and attaching it? – AAlferez May 23 '13 at 13:28
  • 1
    Just creating: Task service = new Task(MainLoop, cancellation.Token, TaskCreationOptions.LongRunning); – astef May 23 '13 at 13:29

1 Answers1

6

You can create the task with several creation option: ie.

var task3 = new Task(() => MyLongRunningMethod(),
                TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness);
task3.Start();
AAlferez
  • 1,480
  • 1
  • 22
  • 48