移动设备中是否存在我的移动应用程序的运行实例 [英] is there a running instance of my mobile application in the mobile device

查看:67
本文介绍了移动设备中是否存在我的移动应用程序的运行实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在移动设备上运行的应用程序,我需要通过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

推荐答案

Google是您的朋友.我在"c#单个应用程序实例"上进行了搜索,并找到了此代码.我不知道它是否有效,但可能有效:

Google is your friend. I googled "c# single app instance" and found this code. I don''t know if it works, but it probably does:

[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.




这篇关于移动设备中是否存在我的移动应用程序的运行实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆