• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Multi-threading and minimizing underutilization of the processor

I'm about to add a second thread to my Windows app. in order to process larger jobs in the background, while providing instant user interface response time in the GUI.  But I'd like to have a maximal amount of processor cycles available to work on that larger job, to bring it to completion sooner rather than later.

My question is, can I allocate 80% (or so) or the processor's time to the larger process, since most of the time spent waiting for user interactions will be time lost?  Or does the ratio come implicitly by design?

I'd love to hear your reply.

1 Solution
Thandava VallepalliCommented:
You can't specify in ratio or percentrage.  But you can specify as thread prority as below.

       Thread threadOne = new Thread(startDelegate);
        threadTwo.Priority = ThreadPriority.Highest;

The Thread can be scheduled before threads with any other priority.

The Thread can be scheduled after threads with Highest priority and before those with Normal priority.

The Thread can be scheduled after threads with Normal priority and before those with Lowest priority.

The Thread can be scheduled after threads with any other priority.

The Thread can be scheduled after threads with AboveNormal priority and before those with BelowNormal priority. Threads have Normal priority by default.

ThreadPriority defines the set of all possible values for a thread priority. Thread priorities specify the relative priority of one thread versus another.

Every thread has an assigned priority. Threads created within the runtime are initially assigned the Normal priority, while threads created outside the runtime retain their previous priority when they enter the runtime. You can get and set the priority of a thread by accessing its Priority property.

Threads are scheduled for execution based on their priority. The scheduling algorithm used to determine the order of thread execution varies with each operating system. The operating system can also adjust the thread priority dynamically as the user interface's focus is moved between the foreground and the background.

The priority of a thread does not affect the thread's state; the state of the thread must be Running before the operating system can schedule it.

ba272Author Commented:
Thanks for the input.  But what priority would the user interface get?  If a thread with infinite amount of work has a higher priority, what is it that eventually gives the control to a lower priority thread.  Relative accrued wait time?


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now