当前位置:网站首页>How does Microsoft solve the problem of multiple PC programs
How does Microsoft solve the problem of multiple PC programs
2022-04-23 03:06:00 【Dotnet cross platform】
Preface
Read an article on the official account. 《C# To solve PC The problem of more open end programs 》.
The author created The mutex Mutex Realized :
bool mutexCreated;
var mutex = new Mutex(true, "MyApp", out mutexCreated);
if (mutexCreated)
{
Application.Run(new Form1());
}
else
{
MessageBox.Show(" The program is already open ");
}
Actually ,VB.NET Of WinForm The program provides a simpler implementation :

No code required , Just tick
Nowadays, few people use VB.NET 了 , Can you migrate the same functions to C# What about China? ?
principle
Compile one VB.NET Of WinForm Program , Decompile the source code , Find the entrance Main Method :

This entry class MyApplication Inherited from WindowsFormsApplicationBase Base class , Of the base class actually executed Run Method .
and Run Method used internally IsSingleInstance attribute , Determine whether to enable Single instance application :

and IsSingleInstance Property is assigned in the constructor of the entry class :
public MyApplication()
: base(AuthenticationMode.Windows)
{
base.IsSingleInstance = true;
base.EnableVisualStyles = true;
base.SaveMySettingsOnExit = true;
base.ShutdownStyle = ShutdownMode.AfterMainFormCloses;
}
Realization
I know the principle , We can transform C# The implementation of the :
class Program : WindowsFormsApplicationBase
{
public Program()
{
IsSingleInstance = true;
}
protected override void OnCreateMainForm()
{
MainForm = new Form1();
}
[STAThread]
static void Main(string[] args)
{
new Program().Run(args);
}
}
Need to quote NuGet package Microsoft.VisualBasic
Next , So let's verify that .
Our program can only be opened once , The first 2 This run will activate the running window .
Conclusion
today , We quote Microsoft.VisualBasic Solve the problem of too many programs !
Want to know more about , Please pay attention to my official account ”My IO“
版权声明
本文为[Dotnet cross platform]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230301334318.html
边栏推荐
- FileNotFoundError: [Errno 2] No such file or directory
- Face longitude:
- SQL statement - DDL
- Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
- Deep q-network (dqn)
- Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
- TP5 where query one field is not equal to multiple values
- Openfeign timeout setting
- 全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
- tf. keras. layers. Density function
猜你喜欢

Summary of interface automation interview questions for software testing

The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot

It turns out that PID was born in the struggle between Lao wangtou and Lao sky

Blazor University (11)组件 — 替换子组件的属性

Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s

Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful

Golden nine silver ten interview season, you are welcome to take away the interview questions (with detailed answer analysis)

宁德时代地位不保?

Ningde's position in the times is not guaranteed?

ASP.NET 6 中间件系列 - 执行顺序
随机推荐
微软是如何解决 PC 端程序多开问题的——内部实现
tf. keras. layers. Conv? D function
使用栈来解决”迷你语法分析器“的问题
求二叉树的叶子结点个数
Array and collection types passed by openfeign parameters
Xamarin效果第二十二篇之录音效果
Using stack to solve the problem of "mini parser"
Judge whether there is a leap year in the given year
TP5 inherits base and uses the variables in base
对.NET未来的一点感悟
If the deep replication of objects is realized through C #?
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
eventBus
Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
LNMP MySQL allows remote access
MAUI初体验:爽
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
.NET7之MiniAPI(特别篇):.NET7 Preview3
Simple example of using redis in PHP