1

In the course or execution, the program may spawn short-running rasks, working on some objects and initializing them if needed. Initialization may cause slight delay.

Also, there is another constantly running task, which is initializing these objects in advance. The observation shows, that it affects overall responsivity. It doesn't happen if the task's thread would have ThreadPriority.Lowest in C# terms.

With traditional multithreading, setting thread priority is straightforward. How to do that with modern concurrency?

  • 1
    custom scheduler with tasks. https://stackoverflow.com/questions/3836584/lowering-priority-of-task-factory-startnew-thread .... do not mess/change thread pools priority....the threads that tasks get executed on. – Colin Smith Dec 19 '21 at 17:34
  • That's a good link, but the best answer is that you're wasting your time barking up the wrong tree if you think thread priorities will solve your problems. It was a bad solution in the old days when only threads existed, and now with async and tasks and whatnot available, it's just horrible to fiddle with thread priorities. Find the problems in your code instead. – Bent Tranberg Dec 19 '21 at 17:42
  • 1
    @CSmith, thanks, I wasn't going to. It is supposed to be adjusted automatically, but not enough for what I need. Looks like, much easier will be to use regular old-fashion thread for that purpose. – Andrei Kalantarian Dec 19 '21 at 17:50
  • @BentTranberg, there are no problems with my code: regular thread outside of a thread pool fits the bill. It just doesn't look right. You are absolutely right about not to fiddle with thread pool priorities. Individual thread outside of a thread pool - different animal. There is nothing horrible if you do it correctly. – Andrei Kalantarian Dec 19 '21 at 18:14
  • If you claim to have that good control of what you're doing, I'm not going to argue against. In my experience many developers misuse thread priorities, and it requires extraordinarily good knowledge to understand when its use is justified. I have only ever used it for a server application that analyzed a great number of live h264 videos simultaneously. – Bent Tranberg Dec 19 '21 at 18:29
  • 1
    @BentTranberg, Yes, I do have a good control, but I believe there is a better way to implement with modern tools. I have decades of experience with regular multithreading (or multitasking on Mainframes) as a handicap. It makes me think of concurrency model as an abstraction layer, which I need to wrap around the familiar base. Will it work - yes. Is it justified - probably not. Will eventually find out. – Andrei Kalantarian Dec 19 '21 at 19:25
  • Custom scheduler works. Thanks all! – Andrei Kalantarian Dec 19 '21 at 20:39

0 Answers0