multithreading - C# Serial DataReceived event starved -
i building on top of existing application , using c# serialport class handle info transactions on usb. i've noticed when application spawns number of long-running threads , not specify them long-running using taskcreation longrunning option, these threads can temporarily starve serialport datareceived event , prevent triggering extended amount of time.
is fundamental result of way in c# handles thread management?
is there way increment "priority" of datareceived event?
if not, "solution" have running thread polls serial port info flags rather using datareceived event?
thanks!
that pretty fundamental, yes. datareceived event handler called thread-pool thread. when you've got many of them active other purposes, tasks not longrunning, can while before event handler gets shot @ running. normal operating scheme scheduling algorithm boosts thread's priority when completes i/o phone call ineffective here, gets tp thread scheduled efficiently :)
this fundamental fire-hose problem, expecting machine accomplish more work can perform. ballpark way know if doing right looking @ task manager. cpu usage should pegged @ 100%. if substantially less not using thread-pool efficiently, some tasks hogging pool not executing plenty code, typically because waiting much on sync object or i/o operation complete. ought prepare that, either using plain thread or taskcreationoptions.longrunning. threadpool.setminthreads() quoted quick fix, dirty one. upgrading machine spec, more cores, cleaner one.
c# multithreading serial-port
No comments:
Post a Comment