Cara Membuat Single Instance App WPF

Deklarasikan pada sub class window:

private static readonly Mutex mutex = new Mutex(false, "singlerunmutex");

[DllImport("USER32.DLL")]
internal static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

Kode cek aplikasi telah berjalan dan merestore window ke depan :

  String appname = Process.GetCurrentProcess().ProcessName;
String appid = Process.GetCurrentProcess().Id;
            Process firstinstance = new Process();
           
            if (!mutex.WaitOne(TimeSpan.FromSeconds(0), false))
            {
                // another instance is already running
                // MessageBox.Show("aplikasi lagi jalan");

                Process[] test = Process.GetProcessesByName(appname);
                foreach (Process p in test)
                {
                    if (p.Id != appid)
                    {
                        firstinstance = p;
                        break;
                    }
                }

                IntPtr WinPtr = firstinstance.MainWindowHandle;

                // Verify there is a mainWindow
                if (WinPtr == IntPtr.Zero)
                {
                    //System.Windows.MessageBox.Show("No Windows");
                    //return;
                }
                else
                {
                    //bring it to front.
                    SwitchToThisWindow(WinPtr, true);
                    
                }

                this.Close();
              
            }

Tutorial Custom ListView di Android

Android Custom Listview with Image and Text using ArrayAdapter