| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Configuration; |
| 4 | using System.Data; |
| 5 | using System.Linq; |
| 6 | using System.Threading.Tasks; |
| 7 | using System.Windows; |
| 8 | |
| 9 | namespace TaiBug |
| 10 | { |
| 11 | ///<summary> |
| 12 | /// |
| 13 | ///</summary> |
| 14 | public partial class App : Application |
| 15 | { |
| 16 | private System.Threading.Mutex mutex; |
| 17 | |
| 18 | private void OnStartup(object sender, StartupEventArgs e) |
| 19 | { |
| 20 | |
| 21 | if (e.Args.Length == 0 || IsRuned()) |
| 22 | { |
| 23 | Shutdown(); |
| 24 | } |
| 25 | } |
| 26 | #region 获取当前程序是否已运行 |
| 27 | ///<summary> |
| 28 | /// |
| 29 | ///</summary> |
| 30 | private bool IsRuned() |
| 31 | { |
| 32 | bool ret; |
| 33 | mutex = new System.Threading.Mutex(true, System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name, out ret); |
| 34 | if (!ret) |
| 35 | { |
| 36 | return true; |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | #endregion |
| 41 | } |
| 42 | } |