I have several window forms object associated with this main window form1 (ie displaybox myDis = new displaybox();), if someone take control of window form (there is displaybox, measurementbox, FFT box all interlinked), it force program to hang and resulting premature timeout delay trigger (in software..see below). This resulted timesenstive program to assumed network failure (which is in fact not) from an instrument using network. (I could consider timeout feature within the TCP socket if there is no data arriving, but let consider this problem anyway)
The aim here is simply if someone moved the window or take control (which cause other inner program to hang) the pause routine become aware and set a flag hence will not generates premature timeout signal. I need to know how to detect such event as described here.
I use Application.Doevent() to keep control available (so I can halt activity process). I avoiding Sleep method because it hang program hence preventing control availability. This routine is not effecient because it take CPU time during the loops.
private void button1_Click(object sender, System.EventArgs e)
string whichwindow = "".
Pause(10000, ref wincontrolstate, ref string whichwindow);
if (wincontrolstate==false) break;
//window associated with this object has moved or interfered, try pause again.
// performs networking activity, waiting to collecting data from an instrument (async operation).
public void Pause(int periodmSec, ref bool wincontrolstate, ref string whichwindow)
ts = endtime.Subtract(starttime);
if (ts.TotalMilliseconds>periodmSec) break;
// if windowmoved or control is detected, set wincontrolstate=true, identify which window (ie window class name) and transfer into whichwindow and then break loop.
I hope to learn more of thread and delegate this afternoon, so I can seperates the window displaybox, measurementbox, FFT box, so that it avoid hanging the main timesenstive routine, but meanwhile let consider the problem above.