Threading Practice with Polling.
Posted
by Stacey
on Stack Overflow
See other posts from Stack Overflow
or by Stacey
Published on 2010-04-30T16:21:44Z
Indexed on
2010/04/30
16:27 UTC
Read the original article
Hit count: 325
I have a C# application that has to constantly read from a program; sometimes there is a chance it will not find what it needs, which will throw an exception. This is a limitation of the program it has to read from.
This frequently causes the program to lock up as it tries to poll. So I solved it by spawning the 'polling' off into a separate thread. However watching the debugger, the thread is created and destroyed each time. I am uncertain if this is typical or not; but my question is, is this good practice, or am I using the threading for the wrong purpose?
ProgramReader
{
static Thread oThread;
public static void Read( Program program )
{
// check to see if the program exists
if ( false )
oThread = new ThreadStart(program.Poll);
if(oThread != null || !oThread.IsAlive )
oThread.Start();
}
}
This is my general pseudocode. It runs every 10 seconds or so. Is this a huge hit to performance? The operation it performs is relatively small and lightweight; just repetitive.
© Stack Overflow or respective owner