Mario van Zeist
Running a CPU at 80% all the time is a dead give away to some serious performance issues. Changing thread priorities has nothing todo with that. it will merely give a thread more chance to complete its work over another (and gives other threads less chance), Having you're CPU running at 80% can also starve system threads from running. For example the system thread that's reading the serialport for you.
This has all been explained by Ilya Tumanov. What i can't understand is why you are using a pollingthread in the first place, why don't you use the DataReceived of the serial port that event will automatically fire when there is data available for you to read. no need to poll for it in a seperate thread.
BUT beware the datareceived event is executed on another thread, NOT the main UI thread, you want to complete your work in that event ASAP, and make damn sure youre not blocking that thread for too long, in short your AdddataBuffer function should complete fast. and make sure you don't change any UI elements in that thread.
As i am using SerialPorts i can tell you they should take 0% processor time, they are extremely slow compared to TCPClient (i still can't understand why you changed from TCPClient to a serialport as they serve complete different purposes), so they don't need alot of processing power.
As stated before, take a hard look at your code and see if youre not needlesly blocking threads from executing, and youre not using some tight loops to check for states in other threads changing. if you know that the code below is one of the worst threading examples ever, youre on the right track.
static bool istheredata =false;
public Init
Thread t = new Thread(Checkme)
t.Start();
while (!istheredata)
{
Donothing();
}
procedure Checkme()
{
Random r = new Random()
while(true)
{
if (r.next(100000000)==774621)
{
istheredata=true;
return;
}
}
}