“制作单实例应用程序"这是做什么的? [英] "make single instance application" what does this do?

查看:27
本文介绍了“制作单实例应用程序"这是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vb 2008 express 中,此选项在应用程序属性下可用.有谁知道它的功能是什么?是不是不能同时打开两个实例?

in vb 2008 express this option is available under application properties. does anyone know what is its function? does it make it so that it's impossible to open two instances at the same time?

推荐答案

还有一个更简单的方法:

There is even a easier method:

使用以下代码...

Imports System.IO

在主表单加载事件上执行以下操作:

On the main form load event do the following:

If File.Exist(Application.StartupPath & "\abc.txt") Then
    'You can change the extension of the file to what ever you desire ex: dll, xyz etc.
    MsgBox("Only one Instance of the application is allowed!!!")
    Environment.Exit(0)
Else
    File.Create(Application.StartupPath & "\abc.txt", 10, Fileoptions.DeleteonClose)
Endif

这将处理单个实例以及瘦客户端,并且在应用程序运行时无法删除文件.并在关闭应用程序或应用程序崩溃时,文件将自行删除.

This will take care of single instances as well as thin clients, and the file cannot be deleted while the application is running. and on closing the application or if the application crashes the file will delete itself.

这篇关于“制作单实例应用程序"这是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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