Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my custom TaskScheduler the default one

I have my own implementation of TaskScheduler. The main reason for its existence is that it will set processor core affinity to the thread running my task.

When I use it in the following manner:

var myTaskSceduler = new MyTaskScheduler(4);
var taskFactory = new TaskFactory(myTaskSceduler);
taskFactory.StartNew(DoSomething);

the affinity works fine, the task will run only on the specified core.

How can I change Task.Factory or Task.Factory.Scheduler so my scheduler will be the default one whenever

 Task.Factory.StartNew()

is being called?

like image 815
Hadar Grubman Avatar asked Apr 24 '14 09:04

Hadar Grubman


1 Answers

Why not just create your own static method, MyTask.StartNew()? Don't you have to specify the affinity as a parameter anyway?

In any case, the task factory should use the same scheduler you're in when you call StartNew. So if you do that on a task on the proper scheduler, it should work just fine. This really depends on how you handle your processing scheduling etc, but I assume you're going to be context dependent anyway if you're not going to be passing the affinity anywhere.

like image 95
Luaan Avatar answered Sep 21 '22 16:09

Luaan