C# Maintain 3 threads and close one if it takes to long -
this code using call 3 threads.
for (int = 0; < 3; i++) { new thread(() => { processeventlogtesting(); }) {isbackground = true }.start(); }
i thinking adjusting this
public static int threadcounter = 0; if (threadcounter < 3) { threadcounter ++; (int = 0; < 3; i++) { new thread(() => { processeventlogtesting(/*somewhere in here code says */threadcounter--;);}) {isbackground = true }.start(); } } }
however, think not best way this. also, want put in new timer says if thread x goes on 20 minutes, kill thread x. appreciated.
since don't know thread does, try
private object lockobject = new object(); private int threadcounter = 0; public int threadcounter { { lock(lockobject) { return threadcounter; } } set { lock(lockobject) { threadcounter = value; } } } //this should method if (threadcounter < 3) { threadcounter ++; new thread(() => { timer t = new timer(() => endthread(), null, 0, 20 * 60 * 1000); while(threadisrunning) { processeventlogtesting(/*somewhere in here code says threadcounter--*/;); } }) {isbackground = true }.start(); } } } private void endthread() { threadisrunning = false; }
Comments
Post a Comment