3
Answers

NO! Don't crash!

Adam Turner

Adam Turner

16y
4.1k
1

Is there any reason why the following code should crash the current windows form it's operating in? It works if I take the screenshot quickly, but if I leave the windows up for a few seconds my windows form gets a little hour glass in front of it and wont respond to anything, then I ussually have to kill it the program the hard way.

 

private void ActiveWindowCaptureAlert()

{

MessageBox.Show("Select the window you want a screenshot of, then press capture!");

while (this.Handle == GetForegroundWindow())

{

Thread.Sleep(10); //sleeping for even 100 seems to make the loop crash

}

while (this.Handle != GetForegroundWindow())

{

hOld = GetForegroundWindow();

Thread.Sleep(10);

}

// ActiveWindowCapture();

}

hOld is a windows handle, as you may have guessed...

Answers (3)