From 89079332852d275d0138acd8b7ecfa4b3fe57863 Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Sat, 9 Dec 2017 10:09:01 -0600 Subject: [PATCH] Switched to VB method of single instance --- GBM/Forms/frmMain.vb | 60 ++++++++++---------------- GBM/My Project/Application.Designer.vb | 2 +- GBM/My Project/Application.myapp | 2 +- GBM/My Project/Resources.Designer.vb | 9 ---- GBM/My Project/Resources.resx | 3 -- 5 files changed, 24 insertions(+), 52 deletions(-) diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index 8fa0238..95b698d 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -1825,53 +1825,37 @@ Public Class frmMain oProcess.StartTime = Now : oProcess.EndTime = Now End Sub - Private Function IsGBMRunning() As Boolean - Dim prsList() As Process = Process.GetProcessesByName("GBM") - If prsList.Length > 1 Then - Return True - Else - Return False - End If - End Function - Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Init Try - 'Ensure only one instance is running - If IsGBMRunning() Then - mgrCommon.ShowMessage(frmMain_ErrorAlreadyRunning, MsgBoxStyle.Exclamation) - ShutdownApp(False) - Else - SetForm() - VerifyGameDataPath() - LoadAndVerify() - If Not bInitFail Then - VerifyCustomPathVariables() + SetForm() + VerifyGameDataPath() + LoadAndVerify() + If Not bInitFail Then + VerifyCustomPathVariables() - If oSettings.StartToTray And Not mgrCommon.IsUnix Then - bShowToggle = False - Me.Visible = False - Me.ShowInTaskbar = False - End If + If oSettings.StartToTray And Not mgrCommon.IsUnix Then + bShowToggle = False + Me.Visible = False + Me.ShowInTaskbar = False + End If - If oSettings.MonitorOnStartup Then - eCurrentStatus = eStatus.Stopped - Else - eCurrentStatus = eStatus.Running - End If + If oSettings.MonitorOnStartup Then + eCurrentStatus = eStatus.Stopped + Else + eCurrentStatus = eStatus.Running + End If - HandleScan() - CheckForNewBackups() + HandleScan() + CheckForNewBackups() - 'Unix Handler - If mgrCommon.IsUnix Then - Me.MinimizeBox = True - Else - Me.gMonTray.Visible = True - End If + 'Unix Handler + If mgrCommon.IsUnix Then + Me.MinimizeBox = True + Else + Me.gMonTray.Visible = True End If End If - Catch ex As Exception If mgrCommon.ShowMessage(frmMain_ErrorInitFailure, ex.Message, MsgBoxStyle.YesNo) = MsgBoxResult.No Then bInitFail = True diff --git a/GBM/My Project/Application.Designer.vb b/GBM/My Project/Application.Designer.vb index cce8b29..c3dd7aa 100644 --- a/GBM/My Project/Application.Designer.vb +++ b/GBM/My Project/Application.Designer.vb @@ -24,7 +24,7 @@ Namespace My _ Public Sub New() MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) - Me.IsSingleInstance = false + Me.IsSingleInstance = true Me.EnableVisualStyles = true Me.SaveMySettingsOnExit = false Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses diff --git a/GBM/My Project/Application.myapp b/GBM/My Project/Application.myapp index 20701f6..6060cf8 100644 --- a/GBM/My Project/Application.myapp +++ b/GBM/My Project/Application.myapp @@ -2,7 +2,7 @@ true frmMain - false + true 0 true 0 diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 7c91d1e..05b6ea4 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -2832,15 +2832,6 @@ Namespace My.Resources End Get End Property - ''' - ''' Looks up a localized string similar to An instance of Game Backup Monitor is already running.. - ''' - Friend ReadOnly Property frmMain_ErrorAlreadyRunning() As String - Get - Return ResourceManager.GetString("frmMain_ErrorAlreadyRunning", resourceCulture) - End Get - End Property - ''' ''' Looks up a localized string similar to GBM is running from a new location, the Windows startup entry has been updated.. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 8ed7679..b68b8d0 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -1945,7 +1945,4 @@ Enable session tracking - - An instance of Game Backup Monitor is already running. - \ No newline at end of file