我如何限制我的申请单次执行? [英] How can I i limit my application for single execution?

查看:64
本文介绍了我如何限制我的申请单次执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.

我是Jvin,是编程的新手..我只是想学习VB.NET,我一直在尝试研究和创建一些简单的应用程序.
作为一个初学者,我创建了一个简单的计算器应用程序,我想知道如何使我的应用程序一次执行..因为每次我双击Calculator.exe时,它总是显示另一种形式的同一应用程序..这样,我只想限制我的可执行文件仅用于单次使用..如果我的应用程序的可执行文件在其已经运行时再次执行,我的应用程序是否可能会首先显示提示消息? ..

有人可以帮我这个忙吗?..对我的学习有很大帮助..


谢谢!...

Good day..

I''m Jvin, a newbie in programming.. i just want to learn VB.NET and i''v been trying to study and create some simple applications..

As a beginner, I''ve created a simple calculator application and i was wondering, thinking of how can i make my application to execute for once.. because every time i double click my Calculator.exe, it always shows another form of the same application.. with this, i just want to limit the use of my executable for single use only.. is it possible for my app to first display a prompt message if the executable file of my app is executed again while its already running?..

would someone help me on this please?.. it would be of a great help for my study..


THANK YOU!...

推荐答案

您所指的是单实例,并且您的标记读取VB.Net,因此它是一个整体容易得多,
转到项目设置

-右键单击,在属性浏览器中单击项目名称,然后选择属性",它是上下文中的最后一项或

-单击菜单栏上的项目",然后在下拉菜单中选择最后一项,应为您的AppName" P roperties或

-按 Alt + P + P .

现在,这将带您进入项目属性,并在 Windows应用程序框架属性下的应用程序"选项卡中,选中/勾选制作单实例应用程序"

要使您的应用程序在另一个实例启动时显示消息,只需向下滚动您所在的页面,然后单击右下角的查看应用程序事件" 按钮. .这将带您到另一个页面,将下面的代码添加到页面中.

You are referring to Single Instancing and since your tag reads VB.Net, it''s a whole lot easier,
Go to project setting by

- Right Click on your project name in the properties explorer and select Properties, it''s the last item in the context or

- Click on Project on the menu bar and select the last item in the drop-down, should be ''Your AppName'' Properties or

- Press Alt + P + P.

Now, this takes you to your project properties and in the Application tab under Windows Application Framework properties check/tick ''Make single instance application''

To make your application show a message when another instance is started, just scroll down on the same page you''re on and click on the button ''View Application Events'' on the bottom right... This takes you to another page add this code below to the page.

Namespace My

    ' The following events are available for MyApplication:
    '
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication
'The code below is what you really need.
        Private Sub MyApplication_StartupNextInstance(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
            MessageBox.Show("An instance of this application is already running!");
        End Sub

    End Class


End Namespace


实例应用程序.您可以使用Microsoft提供的应用程序框架".但是,由于您使用的是VB.NET,因此在创建项目时会有一个选项可以自动嵌入.
That''s a single instance application. You can use the "application framework" provided by Microsoft. But since you are using VB.NET, there is somewhere an option when you create your project to embed that automatically.


这篇关于我如何限制我的申请单次执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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