using System.Configuration;
using System.Data;
using System.Threading;
using System.Windows;

namespace RFIDReaderTC
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static Mutex _mutex = null;
        const string appName = "RFIDReaderTC";
        bool createdNew;

        protected override void OnStartup(StartupEventArgs e)
        {
            _mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                //应用程序已经在运行！当前的执行退出。
                Application.Current.Shutdown();
            }

            base.OnStartup(e);
        }

        public static void Restart()
        {
            // 释放互斥锁
            _mutex.ReleaseMutex();

            string executablePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RFIDReaderTC.exe");
            System.Diagnostics.Process.Start(executablePath);
            //System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);

            Application.Current.Shutdown();
        }
    }

}
