谢谢
解决方案 »
- 问一个c#winform中读取视频的控件的问题
- 请教一下Entity1.Where("xxx").Take(1).Single()如何用反射的方法执行?
- 怎么随机读取数组中的一条记录?
- 在窗体上画好的线,窗体缩小再展开或者线被挡住,线就不见了?
- 关于泛域名的url重写问题
- email代码发送
- C#新手求教,一运行VS2003.net就出错,似乎是不能加载资源文件,这是怎么回事啊?
- 关于水晶报表的文本边框问题
- DataGrid问题:如何获取DataGridTextBoxColumn的双击事件?
- 如果有关于DataGrid的问题请与我联系
- 如何让生成的ws 客户端代码分为几个文件,而不是一个文件?
- 如何在c#中调用c语言中函数,第三方提供了 ipay.h ipay.lib
{
string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;if((System.Diagnostics.Process.GetProcessesByName(procName)).GetUpperBound(0) >0)
{MessageBox.Show("系统已经在运行中...","警告",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Asterisk);
}
else
Application.Run(new FormMain());
}
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
System.Diagnostics.Process[] process = null;
process = System.Diagnostics.Process.GetProcessesByName("WindowsApp");
if (process.Length > 1)
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
Application.Run(new MainForm());
}
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;public class OneInstnace
{
[STAThread]
public static void Main()
{
//得到正在运行的例程
Process instance = RunningInstance();
if (instance == null)
{
//如果没有其它例程,就新建一个窗体
Application.Run (new Form());
}
else
{
//处理发现的例程
HandleRunningInstance(instance);
}
}
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName (current.ProcessName); //遍历正在有相同名字运行的例程
foreach (Process process in processes)
{
//忽略现有的例程
if (process.Id != current.Id)
{
//确保例程从EXE文件运行
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
current.MainModule.FileName)
{
//返回另一个例程实例
return process;
}
}
} //没有其它的例程,返回Null
return null;
} public static void HandleRunningInstance(Process instance)
{
//确保窗口没有被最小化或最大化
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL); //设置真实例程为foreground window
SetForegroundWindow (instance.MainWindowHandle);
} [DllImport("User32.dll")] private static extern bool ShowWindowAsync(
IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")] private static extern bool
SetForegroundWindow(IntPtr hWnd);
private const int WS_SHOWNORMAL = 1;
}
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using JadeSoft.Common;
namespace LogisticsSystem
{
/// <summary>
/// 使应用程序只能运行一个实例 的摘要说明。
/// </summary>
public class AppSingleton
{
static Mutex m_Mutex; public static void Run()
{
if(IsFirstInstance())
{
Application.ApplicationExit += new EventHandler(OnExit);
Application.Run();
}
}
public static void Run(ApplicationContext context)
{
if(IsFirstInstance())
{
Application.ApplicationExit += new EventHandler(OnExit);
Application.Run(context);
}
}
public static void Run(Form mainForm)
{
if(IsFirstInstance())
{
Application.ApplicationExit += new EventHandler(OnExit);
Application.Run(mainForm);
}
else
{
MessageBox.Show("应用程序已启动,请在任务管理中关闭后再启动!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
static bool IsFirstInstance()
{
return true;
m_Mutex = new Mutex(false,"SingletonApp Mutext");
bool owned = false;
owned = m_Mutex.WaitOne(TimeSpan.Zero,false);
return owned ;
}
static void OnExit(object sender,EventArgs args)
{
m_Mutex.ReleaseMutex();
m_Mutex.Close();
}
}using System;
using System.Drawing;
using System.Windows.Forms;
namespace LogisticsSystem
{
/// <summary>
/// 应用程序主入口点。
/// </summary>
public class MainClass
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
AppSingleton.Run(new mainForm());
}
}
}
{
//return true; 这一行注销掉。
m_Mutex = new Mutex(false,"SingletonApp Mutext");
bool owned = false;
owned = m_Mutex.WaitOne(TimeSpan.Zero,false);
return owned ;
}
private static bool instance_flag = false; private Spooler(){
} public static Spooler getSpooler() {
if(!instance_flag)
return new Spooler();
else
return null;
}
}