You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.4 KiB
87 lines
2.4 KiB
using IOTContainer.Common;
|
|
using Microsoft.VisualBasic.ApplicationServices;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Security.Principal;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace IOTContainer
|
|
{
|
|
public class EntryPoint
|
|
{
|
|
[STAThread]
|
|
public static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
SingleInstanceManager manager = new SingleInstanceManager();
|
|
|
|
var identity = WindowsIdentity.GetCurrent();
|
|
var principal = new WindowsPrincipal(identity);
|
|
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
|
|
{
|
|
// 当前正在以管理员权限运行。
|
|
}
|
|
manager.Run(args);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.MyLog.WriteLogFile("出错:" + ex);
|
|
}
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// App.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public App()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public void Activate()
|
|
{
|
|
this.MainWindow.Show();
|
|
this.MainWindow.Activate();
|
|
}
|
|
}
|
|
|
|
public class SingleInstanceManager :
|
|
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
|
|
{
|
|
private App wpfapp; // 这才是真正的WPF Application
|
|
/// <summary>
|
|
/// 单例程序
|
|
/// </summary>
|
|
public SingleInstanceManager()
|
|
{
|
|
this.IsSingleInstance = true;
|
|
}
|
|
|
|
// 第一次打开调这个方法
|
|
protected override bool OnStartup(
|
|
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
|
|
{
|
|
wpfapp = new App();
|
|
wpfapp.Run();
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当有其他应用程序实例化时,则触发此事件,弹出已存在的实例窗口
|
|
/// </summary>
|
|
/// <param name="eventArgs"></param>
|
|
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
|
|
{
|
|
// Subsequent launches
|
|
base.OnStartupNextInstance(eventArgs);
|
|
//wpfapp.Activate();
|
|
}
|
|
}
|
|
}
|
|
|