0

There is a full screen Windows POS Application(Aloha), that contains button, which opens a Windows form. The Form is set to be TopMost=true, ShowIcon = false and ShowInTaskbar = false. Once the button pressed, POS stays open full screen on top of Taskbar with a form above it.

If the form is closed\out of focus, its process exits and everything stays the same. But if button pressed while the form is open, it kills another instances of itself and then Taskbar pops-up on top of POS(once other instances are killed).

KillRunningProcess Function

 private void KillRunningProccess()
{
    try
    {
        Process[] proc = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location));
        Process currentProcess = Process.GetCurrentProcess();
        if (proc != null)
        {
            foreach (Process currProc in proc)
            {
                if (currentProcess.Id != currProc.Id)
                {
                    currProc.Kill();
                }
            }
        }
    }
    catch
    { }
}

I've tried using different PINVOKE API functions on Shown\GotFocus events, without any success. Hiding the taskbar fully is out of the question.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • What you're describing, is this the wanted behavior? Or is this what's happening right now and wish to change? It's unclear to me what exactly you are trying to achieve. What exactly do you wish to happen when you hit the button while the form is already shown? Do you actually want it to close the current form and all processes and launch again? – Oceans Dec 28 '15 at 09:49
  • 2
    That's rather horrible code, clearly you need to address the bug that makes it necessary. Creating a single-instance app is very straight-forward. But yeah, when you randomly kill processes, or for that matter close the window that currently is in the foreground, then the odds that the next window that the OS picks to be the foreground window start to get rather high. You'll have to pinvoke SetForegroundWindow() or use AppActivate() to make it less random. – Hans Passant Dec 28 '15 at 10:02
  • The following topic might be of use to you if you simply want to create a single instance application http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application – Oceans Dec 28 '15 at 10:10

0 Answers0