I have an application which uses WPF for its GUI but, on command kicks off a very heavy processing load. I noticed that my GUI was rather sluggish when the engine (heavy processing) was running and when using the 'Application Timeline' tool in VS2015, I noticed that some of my engine code was being run on the UI thread.
The engine is started with the following line which, if i understand the LongRunning
flag, creates a new thread and runs the given function on that thread.
rootTask = Task.Factory.StartNew(DoWork, TaskCreationOptions.LongRunning);
The DoWork
method referenced above repeatedly uses Parallel.For
to queue up hundreds of tasks.
Is it possible that the dispatcher thread is 'helping-out' by running tasks from the TaskScheduler queue? If so, is it possible to prevent this to keep the GUI responsive (allbeit to the detriment of the background tasks)?
Is it possible that the dispatcher thread is 'helping-out' by running tasks from the TaskScheduler queue?
No, as far as I know, that's not possible. If some code that comes from the Task
really executes on the dispatcher thread, then that means the task had to explicity schedule it there.