加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
App.xaml.cs 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
using GeekDesk.Constant;
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace GeekDesk
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
System.Threading.Mutex mutex;
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
}
private void App_Startup(object sender, StartupEventArgs e)
{
mutex = new System.Threading.Mutex(true, Constants.MY_NAME, out bool ret);
if (!ret)
{
System.Threading.Thread.Sleep(2000);
mutex = new System.Threading.Mutex(true, Constants.MY_NAME, out ret);
if (!ret)
{
Environment.Exit(0);
}
}
}
}
// private void WriteLog(object exception)
// {
// Exception ex = exception as Exception;
// using (FileStream fs = File.Open(".//ErrorLog.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
// {
// fs.Seek(0, SeekOrigin.End);
// byte[] buffer = Encoding.Default.GetBytes("-------------------------------------------------------\r\n");
// fs.Write(buffer, 0, buffer.Length);
// buffer = Encoding.Default.GetBytes(DateTime.Now.ToString() + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// if (ex != null)
// {
// buffer = Encoding.Default.GetBytes("成员名: " + ex.TargetSite + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// buffer = Encoding.Default.GetBytes("引发异常的类: " + ex.TargetSite.DeclaringType + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// buffer = Encoding.Default.GetBytes("异常信息: " + ex.Message + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// buffer = Encoding.Default.GetBytes("引发异常的程序集或对象: " + ex.Source + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// buffer = Encoding.Default.GetBytes("栈:" + ex.StackTrace + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// }
// else
// {
// buffer = Encoding.Default.GetBytes("应用程序错误: " + exception.ToString() + "\r\n");
// fs.Write(buffer, 0, buffer.Length);
// }
// }
//}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化