# Thread at realtime priority (C#)



## MrSeanKon (Jun 1, 2007)

Is it possible???
OK in Visual C++ we can (although it is a bit tricky) but I am wondering if we can under C#.


----------



## W1zzard (Jun 1, 2007)

yes its possible look at Thread.Priority property


----------



## MrSeanKon (Jun 1, 2007)

Thanks for the reply W1zzard but Thread.Priority property has the options (some of them) Normal, AboveNormal and Highest.
I think Highest priority is equivalent to run a program at High priority.


----------



## W1zzard (Jun 1, 2007)

you could pinvoke the setthreadpriority api call .. but generally thisis a really bad idea because you probably hang the system if something goes wrong.


----------



## MrSeanKon (Jun 14, 2007)

Thanks again W1zzard.
I was wondering yesterday if API is the only solution to do this.
BTW the Highest priority stretches enough any system.


----------



## TheMasterOfSinanju (Jun 18, 2007)

W1zzard said:


> you could pinvoke the setthreadpriority api call .. but generally thisis a really bad idea because you probably hang the system if something goes wrong.



On a dual cpu (multicore setup too) true SMP rig, or a multicore one? This IS doable... but, not on a singlecore system (this WILL lock it up, or make it appear to be so).

Some "FYI"... now, you CAN put in CPU ceding calls in say, a loop you run @ realtime priority, but is it smart to do? You are out to get as MUCH cpu as you can when you set this after all... & doing a (for example in VB, DoEvents OR Sleep API call, or Delphi Application.ProcessMessages or Sleep API call) sort of defeats the purpose of it!

However, & I have run into this? You can make a program use it, but if you DON'T put in at least 1 cpu ceding type function/api call?? You won't even be able to move the screen of the app you are running this in!

That's what I have seen in it.

APK

P.S.=> In VB.NET, one thing I have learned is, yes... you CAN call the Win32 API & do process priority control, as I have put into this app:

http://www.techpowerup.com/downloads/389/foowhatevermakesgooglehappy.html

BUT, that's done in Delphi (fastest language there is, especially in math & strings (proven over VB & MSVC in "VB Programmers Journal" issue "INSIDE THE VB5 COMPILER ENGINE" October 1997 issue in fact) & EVERY program does math & strings work, and Delphi blew the doors out of VB in 9/10 tests (lost in ActiveX form loads, but even MSVC++ lost to VB there), & blew out MSVC++ in 8/10 tests also iirc)...  this is WHY I chose it for that app in fact (heavy strings work mostly).

.NET apps use the common runtimes, & keep you "safe (r)", but anytime you step out of there, using the underlying Win32 API in API calls to set process or thread priorities? You are potentially sacrificing that protection (but, this only has to occur once @ the launch of your app really, if you intend to use realtime process priority).

AND, I do NOT recommend using Win32 API calls in ASP.NET... not the same "idea" as doing VB.NET stuff. More "web/sessions" oriented. Stay as ASP/ASP.NET here, as you can!

Hope you guys are "getting this", it is just what I have run into playing with this stuff... and, if you go about it using multiple thread design & doing API calls like SetThreadPriority?

Be SURE your threads you use it on actually are busy, & can saturate a processor well... otherwise? What is the point imo??

After all - setting highest cpu priority is only valid/useful in an application @ process level, OR even thread level, IF they can keep a CPU busy! apk


----------

