?
Solved

How to set the Thread priority AfxBeginThread

Posted on 2005-04-30
2
Medium Priority
?
1,583 Views
Last Modified: 2013-11-20
Hi experts,
I ran into problems, using this:
DWORD priority = TranslatePriority("Low");
AfxBeginThread(WorkThread,this,int(priority),0);
For some strange reason this crashes.
Any ideas?

Priority is generated from a CComboBox like this:
DWORD CAutoPeaksDlg::TranslatePriority(string str){
      DWORD ret = IDLE_PRIORITY_CLASS;
      if(str == "Highest")
            ret = REALTIME_PRIORITY_CLASS;
      if(str == "High")
            ret = HIGH_PRIORITY_CLASS;
      if(str == "Above Normal")
            ret = ABOVE_NORMAL_PRIORITY_CLASS;
      if(str == "Normal")
            ret = NORMAL_PRIORITY_CLASS;
      if(str == "Below Normal")
            ret = BELOW_NORMAL_PRIORITY_CLASS;
      if(str == "Low")
            ret = IDLE_PRIORITY_CLASS;
      return(ret);
}
Thanks,
Jens
0
Comment
Question by:allmer
2 Comments
 
LVL 9

Accepted Solution

by:
rcarlan earned 1000 total points
ID: 13904002
First of all, to answer your question, priority classes are for processes not for threads.

Use

THREAD_PRIORITY_IDLE
THREAD_PRIORITY_LOWEST
THREAD_PRIORITY_BELOW_NORMAL
THREAD_PRIORITY_NORMAL
THREAD_PRIORITY_ABOVE_NORMAL
THREAD_PRIORITY_HIGHEST
THREAD_PRIORITY_TIME_CRITICAL

for threads.


Secondly, just as a general comment, you may want to either replace the ifs with else-ifs or return as soon as you have a match. Your implementation of TranslatePriority is rather inefficient because it compares against all strings even after finding a match.

Radu

0
 
LVL 5

Author Comment

by:allmer
ID: 13907156
Thanks Radu,
I got mixed up there.
And yes you are right about the implementation, i'll switch it.
Best,
Jens
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question