Search code examples
c#cpu-speed

Running parts of my application on a different CPU priority


Got a winform C# application.

It allows a stream of images to be displayed (like a video).

I also upload these jpegs 1 at time to my web server and a User can view these jpegs (like a video).

In the quest to make my code as efficient as possible I was wondering whether I can execute the part of my code that is responsible for uploading these images under a different priority - like real time for instance?

Is this possible?

If so..

Do I have to port my class object responsible for uploading these images into an external DLL? Then how would I 'launch' it under a different process priority?

If all this is possible, and If I accept the possible trade off of other processes on my PC which may be affected by all this will it actually give me an improved performance?

Thanks


Solution

  • I do not think the threads priorities will help you to solve the problem but if you want yes you can change the threads priority in C# and you have also a a lot of libraries which are helping you to control the thread workflow like

    • TPL, PLINQ
    • Tasks
    • Async, Await
    • BackgroundWorker
    • Threads etc C#.

    TPL for Task Parallel Library very powerful on multi processors.

    Think carefully before elevating a thread’s priority — it can lead to problems such as resource starvation for other threads.

    using (Process p = Process.GetCurrentProcess())
      p.PriorityClass = ProcessPriorityClass.High;
    
    enum ThreadPriority { Lowest, BelowNormal, Normal, AboveNormal, Highest }
    

    I recommnded you to use encoding/decoding for the images this will help you to convert a sequence of images to video. look to this link:

    Rendering a Sequence of Images in C# to make a video