none
Programatically Setting the Priority of the Windows Service to Low.

    Question

  • Hello,

    I have written a windows service. But the service priority is normal.

    I need to set the priority to low or lowest. Does anyone know how to do this programatically using C#.

     

    Thanks In Advance

    With Regards

    Sunil Dutt

    Wednesday, December 20, 2006 3:10 PM

Answers

  • Use this line of code at startup (and add the System.Diagnostics namespace):

    Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;

    Friday, December 22, 2006 10:55 AM

All replies

  • I 'm not sure what you mean with service priority. If you mean the priority as indicated in the task manager than you could try change the priority with Windows Management Instrumentation. Generate a class for processes and use it in c# to find your proces and change the priority.
    Wednesday, December 20, 2006 4:19 PM
  • Another alternative is to use the WinAPI SetPriority function.
    Wednesday, December 20, 2006 4:33 PM
  • Yes, Priority of the Service means the Priority as indicated in the task manager. I tried by assigning the AppParameters in the Regedit to -p 64 but my service is still showing priority as Normal and not as Low.
    Friday, December 22, 2006 9:06 AM
  • Can you please assist this with a Sample Code.
    Friday, December 22, 2006 9:07 AM
  • Use this line of code at startup (and add the System.Diagnostics namespace):

    Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;

    Friday, December 22, 2006 10:55 AM