If your application performs long operations sometimes and you do not want to spend time writing specialized code to show an indicator in every such place, then this class might help you.
The idea is very simple. User actions such as keyboard and mouse events are just window messages. So, we can assume that your application is locked (processing a long operation) when your GUI thread (main thread, in most cases) can not process window messages.
LockDetector class periodically calls
BeginInvoke on some control from the target thread to send a window message. Then, if the delegate has not been called during a specified timeout interval, the
OnLockDetected event is called in the detector thread and then can be processed in parallel with the thread being monitored.
Using the code
Check this very short example of how to use the class:
private LockDetector detector;
private void TestForm_Load(object sender, EventArgs e)
detector = new LockDetector(this, 300);
detector.OnLockDetected += new
detector.OnLockFinished += new
private void TestForm_FormClosing(object sender, FormClosingEventArgs e)
detector = null;
private void button1_Click(object sender, EventArgs e)
The sources include a more advanced example.
- 06 Apr 2008 - Initial release.