Solved

Base Priority

Posted on 2003-11-08
6
319 Views
Last Modified: 2013-11-20
Hi

How do I change my app's default Base Priority from the default 8 to a higher value.
I done the following but it had no effect

  HANDLE hProc = GetCurrentThread();
  SetThreadPriority(THREAD_PRIORITY_HIGHEST);


0
Comment
Question by:Dj_Fx8
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9707575
SetPriorityClass(GetCurrentProcess(), ...);

All threads in the process get this priority. SetThreadPriority changes relative priority from the value set by SetPriorityClass.
0
 

Author Comment

by:Dj_Fx8
ID: 9742613
Hi Alex
Sorry for the delay I thought I had posted this a few days ago. I tried what you said but it had no effect I put the code in CMyApp::InitInstance, should it be somewhere else
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9745636
Yes, it should be in InitInstance. Please show your code, this should work.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Dj_Fx8
ID: 9758496
Hi Alex
Here the whole InitInstance

// CDjMM8App initialization

BOOL CDjMM8App::InitInstance()
{
      AfxEnableControlContainer();

      // Standard initialization
      // If you are not using these features and wish to reduce the size
      //  of your final executable, you should remove from the following
      //  the specific initialization routines you do not need.
/*      if(!AfxOleInit())
      {
            AfxMessageBox(_T("Ole Initialization failed"));
            return FALSE;
      }*/

      AfxGetModuleState()->m_dwVersion = 0x0601;

#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif

//      HANDLE hProc = GetCurrentThread();
      
///******H E R E   I S    Y O U R    C O D E
      SetPriorityClass(GetCurrentProcess(),16);

      // Set Registry Key
      SetRegistryKey(_T("KaS Software"));

      LoadStdProfileSettings();  // Load standard INI file options (including MRU)

      //** create the font I want to use throught the app
      m_ghFontTahoma90 = new CFont;
      VERIFY(m_ghFontTahoma90->CreatePointFont(90, _T("Tahoma")));

      //** Create the coloured brushes
      g_pbrWheat = new CBrush;
      g_pbrWheat->CreateSolidBrush(RGB(255,209,204));
      g_pbrTomatoe = new CBrush;
      g_pbrTomatoe->CreateSolidBrush(RGB(255,99,71));
      g_pbrPage = new CBrush;
      g_pbrPage->CreateSolidBrush(RGB(255,228,210));
      g_pbrBlack = new CBrush;
      g_pbrBlack->CreateSolidBrush(RGB(0,0,0));
      g_pbrRed = new CBrush;
      g_pbrRed->CreateSolidBrush(RGB(255,0,0));
      g_pbrGreen = new CBrush;
      g_pbrGreen->CreateSolidBrush(RGB(0,255,0));
      g_pbrYellow = new CBrush;
      g_pbrYellow->CreateSolidBrush(RGB(250,240,30));


      // Register the application's document templates.  Document templates
      //  serve as the connection between documents, frame windows and views.
      CSingleDocTemplate* pDocTemplate;
      pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(CDjMM8Doc),
            RUNTIME_CLASS(CMainFrame),       // main SDI frame window
      RUNTIME_CLASS(CDjMM8View));
      AddDocTemplate(pDocTemplate);

      // Parse command line for standard shell commands, DDE, file open
      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

      // The one and only window has been initialized, so show and update it.
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();


      //Initalise BASS
      if (!BASS_Init(1,44100,0,0,NULL)){
            CString szTemp;
            szTemp.Format("%d",BASS_ErrorGetCode());
            AfxMessageBox("The Audio Engine could not be initialised.\nIf the problem persists restart the computer\nError Code:" + szTemp + "\nBas Init", MB_ICONSTOP | MB_OK);
            AfxGetMainWnd()->PostMessage(WM_CLOSE);
      }
      BASS_Start();


      return TRUE;
}
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 9758563
You can use the following constants with SetPriorityClass:

ABOVE_NORMAL_PRIORITY_CLASS       0x00008000
BELOW_NORMAL_PRIORITY_CLASS       0x00004000
HIGH_PRIORITY_CLASS                         0x00000080
IDLE_PRIORITY_CLASS                          0x00000040
REALTIME_PRIORITY_CLASS                 0x00000100

Read their description in MSDN topic SetPriorityClass and select one of them. Don't use hard-coded values.
You can check this code in the Task Manager. Right-click the process and select Set Priority. Current process priority is checked.
0
 

Author Comment

by:Dj_Fx8
ID: 9759953
Hi Alex
That got it sorted many thanks

Steven
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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