1.比较两个日期时间相差秒数
private int DateDiff(DateTime dt1, DateTime dt2)
{
return dt1.Subtract(dt2).Seconds;
}
2. 程序单实例启动
Bool isStart;
Var mutexRunningSingle = new Mutex(true, “程序唯一标识”, out isStart);
If (!isStart)
{
Current.Shutdown(1);
}
3.主程序需要捕获的异常
static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e){}
static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
//当前应用程序的页面调度异常
Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
//当前应用程序域中的所有未处理的异常
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
4.创建通知图标
NotifyIcon _notifyIcon;
Private void OnExit(object sender, EventArgs e){}
private void OnNotifyIconDoubleClicked(object sender, EventArgs e){}
ToolStripButton btn = new ToolStripButton
{
Text = “Exit”
};
btn.Click += OnExit;
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
contextMenuStrip.Items.Add(btn);
_notifyIcon = new NotifyIcon
{
Text = “SystemName”,
Icon = DataShow.Properties.Resources.AppSymbol,
Visible = true,
ContextMenuStrip = contextMenuStrip,
};
_notifyIcon.DoubleClick += OnNotifyIconDoubleClicked;
5.动态加载程序集
Assembly.LoadFrom(“程序集路径及文件名”);
6. 以默认类型创建实例
Activator.CreateInstance(Type);
7. 在WPF中使用WinForm控件
使用System.Windows.Forms.Integration命名空间下WindowsFormsHost进行包装