[STAThread] static void Main() { bool isCanStart; System.Threading.Mutex mutex = new System.Threading.Mutex(false, "AA", out isCanStart); if (isCanStart) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new form1()); } else { MessageBox.Show("程序已运行!"); } }
用互斥体Mutex,一个同步基元,也可用于进程间同步 using System; using System.Collections.Generic; using System.Text; using System.Threading;namespace ConsoleApplication1 { class Program { private static Mutex mutex; static void Main(string[] args) { bool create = false; mutex = new Mutex(true, "应用程序名", out create); if (create) { Console.WriteLine("abc Runing"); Console.Read(); } } } }
[STAThread]
static void Main()
{
bool isCanStart;
System.Threading.Mutex mutex = new System.Threading.Mutex(false, "AA", out isCanStart);
if (isCanStart)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new form1());
}
else
{
MessageBox.Show("程序已运行!");
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;namespace ConsoleApplication1
{
class Program
{
private static Mutex mutex;
static void Main(string[] args)
{
bool create = false;
mutex = new Mutex(true, "应用程序名", out create);
if (create)
{
Console.WriteLine("abc Runing");
Console.Read();
}
}
}
}
防止二次启动:在注册表里设置一个标识,启动前根据标识判断是否启动。
{
private static Mutex mutex;
static void Main(string[] args)
{
bool create = false;
mutex = new Mutex(true, "应用程序名", out create);
if (create)
{
Console.WriteLine("abc Runing");
Console.Read();
}
}
}
写在主程序的program
可是怎么能让程序界面隐藏我还没找到方法
a8cake说改变窗体的透明度,大小,可见性,这些属性我怎么没在FORM属性里找到呢??请高手指点!!谢谢~~
this.ShowInTaskbar = false;
WindowState = FormWindowState.Minimized;
要显示的时候在notifyIcon的MouseUp加代码就可以
如:
private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Form1 form = new Form1();
form.ShowDialog();
}
}
或者是left或者top=-20000;
visible和hide这两个方法都不管用呀~~9楼的方法管用!!呵呵~~多谢大家了