Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!...
Posted
Updated 16-Oct-12 17:35pm
v2

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.

VB
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
 
Share this answer
 
Comments
jlhai 18-Oct-12 2:16am    
Thank you very much for the help... i'm glad that i've got helpful solution...

God Bless.. two thumbs up for this!.. :-)
Akinmade Bond 18-Oct-12 5:53am    
Well, you didn't mark the answer as solution nor did you vote it. :) So, please do.
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900