I want to call ShowDialog() when a keyboard hook event is triggered, but I’m having some difficulties:
- ShowDialog() blocks, so I can’t call it from the hook triggered event, because it will block the OS.
- I can start a new thread and call
ShowDialog()from there, but I get some nasty exception. I guess I can’t callShowDialog()in any other thread. - I can start a timer: in the next 50 milliseconds call
ShowDialog()(which is a nasty hack BTW, and I rather not do this). But then the timer fires in a new thread, and then I run into the same problem explained in the previous bullet.
Is there a way?
The problem may be that you are trying to put UI in a non-UI thread. Make your event fire from another thread and invoke the method that runs
ShowDialog()from your UI thread.Essentially, you want to keep your UI on the UI thread and move anything else to a back ground thread.
Check out Gekki Software for some details (there are zillions of others – this just happens to be the first one I found in research archives).