当前位置:网站首页>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
边栏推荐
- Redis Cluster集群,主节点故障,主从切换后ip变化,客户端需要处理不
- .NET7之MiniAPI(特别篇):.NET7 Preview3
- SQL statement - DDL
- The space between the left and right of the movie ticket seats is empty and cannot be selected
- Restart redis
- Recursion - outputs continuously increasing numbers
- Openfeign timeout setting
- 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
- 准备一个月去参加ACM,是一种什么体验?
- C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
猜你喜欢
Niuke white moon race 5 [problem solving mathematics field]
Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
Openfeign timeout setting
tf. keras. layers. Timedistributed function
PDH optical transceiver 4-way E1 + 4-way 100M Ethernet 4-way 2m optical transceiver FC single fiber 20km rack type
What kind of experience is it to prepare for a month to participate in ACM?
ASP.NET 6 中间件系列 - 条件中间件
Summary of software test interview questions
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)
Recursion - outputs continuously increasing numbers
随机推荐
微软是如何解决 PC 端程序多开问题的
Blazor University (11) component - replace attributes of subcomponents
Publish to NPM?
Array and collection types passed by openfeign parameters
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
TP5 email (2020-05-27)
Systemctl start Prometheus + grafana environment
Wepy learning record
Creating wechat voucher process with PHP
Passing object type parameters through openfeign
Depth deterministic strategy gradient (ddpg)
How to count the number of all files in a directory under win10 system
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
C# 读写二进制文件
Openfeign timeout setting
中后二叉建树
Laravel8- use JWT
7-11 重排链表 (25 分)
利用正反遍历来解决“字符的最短距离”问题