本文介绍了移动设备中是否存在我的移动应用程序的运行实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正在移动设备上运行的应用程序,我需要通过C#代码检查此应用程序是否正在运行.
Plzzzzzzzzzzzzzzzzzzz help
I have an application that is running on a mobile, i need to check if there is a running instance of this application by C# code.
Plzzzzzzzzzzzzzzzzz help
推荐答案
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
顺便说一句,停止在您的消息中使用"Plzzzzzzzzzzzz".只是惹恼了这里的所有人.
BTW, stop using "Plzzzzzzzzzz" in your messages. It just pisses everyone here off.
这篇关于移动设备中是否存在我的移动应用程序的运行实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!