Hi,
" How to allow a background thread to bring a window in foreground"
If someone can help to come out of this problem.
I wanted to create an application whoes only one instance should run at a time from within a folder.
There are many ways to do this, but I followed this one.
Implementation:
- Create an event with some uniq name (with foler name) "Onlyone+Inst1" .
- Check if that event already created by another instance
- If first Instance then, Create a thread. The thread method (screen monitor) will wait for event to set.
- If another instance then, set the event and exit.
- If ScreenMonitor finds the event set, its job now is to bring the instance in the foreground, otherwise just waits for the event.
------
Now, it works fine but it does not bring the first instance in foreground all the time. Yes sometime it does and other itmes it blinks in the taskbar.
There is no surprise for this behaviour. I have tried all these method for this purpose and information can be find on msdn. none of them helped.
SetForegroundWindow()
SystemParametersInfo()
AllowSetForegroundWindow(ASFW_ANY)
SwitchToThisWindow()
BringWindowToTop()
----
I can use alternate method, but I want to do this way as do not see any reason for not working.
regards,
-op
" How to allow a background thread to bring a window in foreground"
If someone can help to come out of this problem.
I wanted to create an application whoes only one instance should run at a time from within a folder.
There are many ways to do this, but I followed this one.
Implementation:
- Create an event with some uniq name (with foler name) "Onlyone+Inst1" .
- Check if that event already created by another instance
- If first Instance then, Create a thread. The thread method (screen monitor) will wait for event to set.
- If another instance then, set the event and exit.
- If ScreenMonitor finds the event set, its job now is to bring the instance in the foreground, otherwise just waits for the event.
------
Now, it works fine but it does not bring the first instance in foreground all the time. Yes sometime it does and other itmes it blinks in the taskbar.
There is no surprise for this behaviour. I have tried all these method for this purpose and information can be find on msdn. none of them helped.
SetForegroundWindow()
SystemParametersInfo()
AllowSetForegroundWindow(ASFW_ANY)
SwitchToThisWindow()
BringWindowToTop()
----
I can use alternate method, but I want to do this way as do not see any reason for not working.
regards,
-op