■■■

2016年4月9日土曜日

二重起動を禁止する方法

Microsoft Visual Studio Professional 2012 通常版
二重起動を禁止する方法

Mainの先頭(一番最初)で二重起動チェックをします。

VB.NET
    ''' <summary>
    ''' 二重起動を禁止する方法
    ''' </summary>
    ''' <returns></returns>
    Public Shared Function ExixtsSameApp() As Boolean
        ' 現在のアプリ名を取得
        Dim stThisProcess As String = System.Diagnostics.Process.GetCurrentProcess().ProcessName

        ' 同じ名前が存在するか確認する方法
        If System.Diagnostics.Process.GetProcessesByName(stThisProcess).Length > 1 Then
            Return True
        End If

        ' 存在しない場合
        Return False

    End Function

Microsoft Visual Studio Professional 2012 通常版

C#
        /// <summary>
        /// 二重起動を禁止する方法
        /// </summary>
        /// <returns></returns>
        public static bool ExixtsSameApp()
        {
            // 現在のアプリ名を取得
            string stThisProcess = System.Diagnostics.Process.GetCurrentProcess().ProcessName;

            // 同じ名前が存在するか確認する方法
            if (System.Diagnostics.Process.GetProcessesByName(stThisProcess).Length > 1)
            {
                return true;
            }

            // 存在しない場合
            return false;

        }

Microsoft Visual Studio Professional 2012 通常版
■■■