public class Program
{
public Program()
{
}
private const string lockfile="mylock.txt";
public static void Main()
{
FileStream fs=null;
if(File.Exists(lockfile))
{
try
{
fs=File.Open(lockfile,FileMode.Append,FileAccess.Write,FileShare.None);
}
catch(System.IO.IOException ex)
{
MessageBox.Show("程序只允许一个实例在运行");
System.Environment.Exit(System.Environment.ExitCode);
}
}
else
{
fs=File.Create(lockfile);
}
Form1 tes=new Form1();
Application.Run(tes);
}
}
{
public Program()
{
}
private const string lockfile="mylock.txt";
public static void Main()
{
FileStream fs=null;
if(File.Exists(lockfile))
{
try
{
fs=File.Open(lockfile,FileMode.Append,FileAccess.Write,FileShare.None);
}
catch(System.IO.IOException ex)
{
MessageBox.Show("程序只允许一个实例在运行");
System.Environment.Exit(System.Environment.ExitCode);
}
}
else
{
fs=File.Create(lockfile);
}
Form1 tes=new Form1();
Application.Run(tes);
}
}