当前位置:网站首页>C # judge whether the application is started and displayed
C # judge whether the application is started and displayed
2022-06-22 02:10:00 【coder i++】
[STAThread]
private static void Main()
{
Process process = publicClass.RunningInstance();
if(process!=null)
{
publicClass.HandleRunningInstance(process);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatiableTextRenderingDefault(false);
Application.Run(new FormName());
}
}
Show form
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
internal class publicClassa
{
public static void HandleRunningInstance(Process instance)
{
publicClass.ShowWindowAsync(instance.MainWindowHandle, 1);
publicClass.SetForegroundWindow(instance.MainWindowHandle);
}
public static Process RunningInstance()
{
Process process;
Process currentProcess = Process.GetCurrentProcess();
Process[] processesByName = Process.GetProcessesByName(currentProcess.ProcessName);
int num = 0;
while (true)
{
if (num < (int)processesByName.Length)
{
Process process1 = processesByName[num];
if (process1.Id != currentProcess.Id)
{
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == currentProcess.MainModule.FileName)
{
process = process1;
break;
}
}
num++;
}
else
{
process = null;
break;
}
}
return process;
}
[DllImport("User32.dll", CharSet=CharSet.None, ExactSpelling=false)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("User32.dll", CharSet=CharSet.None, ExactSpelling=false)]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
}
边栏推荐
- 谁会用pyspark将筛选过后本地数据上传到spark sql
- acwing 838. Heap sort (write a heap)
- [phantom engine UE] package error appears! Solutions to findpin errors
- 微信小程序影视评论交流平台系统毕业设计毕设(2)小程序功能
- 【 NVIDIA development history record 618-01 】
- 数组常用方法
- Audio and video learning route and learning materials recommendation
- word文档转markdown文档?
- Appium interview questions
- Games-101 personal summary rasterization
猜你喜欢

flutter系列之:flutter中的IndexedStack

Wechat applet film and television review and exchange platform system graduation design completion (8) graduation design thesis template

1277_FreeRTOS中vTaskDelay的实现分析

acwing 836. Merge sets (merge sets)

Chapter 08 handwritten digit recognition based on knowledge base matlab deep learning application practice
![[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]](/img/2f/b2f141bf2f0b1f2f80444d37529a9b.png)
[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]

Lianfa science and technology -- Introduction to Lianfa science and technology ++ attached

Machine learning compilation lesson 1: overview of machine learning compilation
![[chapter 02 weight adaptive image denoising technology based on Morphology - full system matlab intelligent driving in-depth learning]](/img/65/c9ba18ffd37f84c3ca399507625c90.png)
[chapter 02 weight adaptive image denoising technology based on Morphology - full system matlab intelligent driving in-depth learning]

Appium面试题
随机推荐
理财产品到期赎回时间是什么意思?
Shell脚本语法概览
Learn to crawl steadily 08 - detailed explanation of the use method of selenium
What is a neural network
微信小程序影视评论交流平台系统毕业设计毕设(7)中期检查报告
[phantom engine UE] package error appears! Solutions to findpin errors
回到成都开启我的软件测试职业生涯
What is your understanding of interface testing?
Error reporting and table layout of latex on &
[chapter 01 image defogging technology based on histogram optimization - full system matlab intelligent driving depth learning]
No sleep at noon, sleepy in the afternoon
LeetCode 41 - 45 动态规划专题
Audio and video learning route and learning materials recommendation
2019 csp-j1 csp-s1 first round preliminary round answer analysis and summary, video, etc
Chapter 09 English printed character recognition based on feature matching matlab deep learning practical case
Zhongang Mining Co., Ltd.: fluorite is a scarce resource with enhanced attributes, and there may be a gap between supply and demand in the future
[Chapter 15 wavelet based image compression technology deep learning machine learning image processing application matlab.]
excel常用快捷鍵excel快捷鍵匯總
Who will use pyspark to upload filtered local data to spark SQL
快速学会CAD绘制传输线路图纸