Capture all key presses in context. Have a flag the event handler and your thread or logic around your thread can access. Set the flag to indicate state. Determine whether or not to cancel the key press by the state of the flag.
∞ Andy Badera ∞ +1 518-641-1280 ∞ This email is: [ ] bloggable [x] ask first [ ] private ∞ Google me: http://www.google.com/search?q=(andrew badera) OR (andy badera) On Mon, Sep 7, 2009 at 8:04 AM, Benj Nunez<[email protected]> wrote: > > Hello experts, > > I need your help. I have code which uses thread. I'm not sure if I'm > doing this correctly (my comments > inserted in the code below): > > > WaitForm waitForm = new WaitForm(); > waitForm.Show(); > > thrdParam = new Thread(new ParameterizedThreadStart > (runThreadedQuery)); > thrdParam.Start(strQuery); > > menuStrip.Enabled = false; > btnExecute.Enabled = false; > TabControl.Enabled = false; > > while (thrdParam.IsAlive) > { > waitForm.Refresh(); > /* Maintains that the Waitform's close box is > disabled. > But the MainForm still "remembers" the keys > pressed. > (e.g. alt+f4). So far, only ALT+F4 is trapped. > I have code > under MainForm_FormClosing() which has a prompt > before closing. */ > } > > waitForm.Close(); > dgvQueryResult.Focus(); > menuStrip.Enabled = true; > btnExecute.Enabled = true; > TabControl.Enabled = true; > > > While a thread is running, I intentionally keep pressing shortcut keys > like ALT+H+B to show > the "About" window (which will not appear yet because of the loop). > When the thread ends, the "About" window appears because it has > "remembered" my keystrokes. > > I want the main form to ignore whatever key was pressed. How do I > suspend/resume key events. > Is it possible? Am I doing this correctly? Please help. > > > > Benj > >
