473,466 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Run only once

Hello

I want to make an aplication that runs only one time

Let me explain better, each time I click on 'calculator' icon, it will open several 'calculators'

What I want to do is to make a aplication that, if I click is icon it will open the aplication, if the aplication is already open it will 'bring it to front' instead of open a new aplication

Thank's in advanc

Luis Mendes
Nov 20 '05 #1
4 1186
Hi Luis,

When you speak a little bit German I would look here, it gives the best
solutions.
http://dotnet.mvps.org/dotnet/code/application/

"Nur eine etc.

Without the German you can have a look at the code and if that not succeed
as well than

Single instance
http://msdn.microsoft.com/library/de...eaworapps1.asp
I hope this helps a little bit?

Cor

I want to make an aplication that runs only one time.

Let me explain better, each time I click on 'calculator' icon, it will open several 'calculators'.
What I want to do is to make a aplication that, if I click is icon it will open the aplication, if the aplication is already open it will 'bring it to
front' instead of open a new aplication.

Thank's in advance
Luis Mendes

Nov 20 '05 #2
Here is the code I am using (although it does not bring the "running
instance to the front", sounds like a good idea).

Option Strict On
Imports System.Threading

Module Main
Private Sub SubMain()

SingletonApp.Run(New MyForm)

End Sub
Enc Module
Public Class SingletonApp

Shared m_Mutex As Mutex
Public Shared Sub Run(ByVal mainForm As Form)
If (IsFirstInstance()) Then
AddHandler Application.ApplicationExit, AddressOf OnExit
Application.Run(mainForm)
End If
End Sub
Public Shared Function IsFirstInstance() As Boolean

' use this to create a unique guid for your app...
'Dim g As New Guid
'g = Guid.NewGuid
'Debug.WriteLine(g.ToString)

m_Mutex = New Mutex(False, "8ca35a66-6e9a-41d4-a87d-d9755b1f88c4") '
arbitrary GUID
Dim owned As Boolean = False
owned = m_Mutex.WaitOne(TimeSpan.Zero, False)
Return owned
End Function

Public Shared Sub OnExit(ByVal sender As Object, ByVal args As
EventArgs)
m_Mutex.ReleaseMutex()
m_Mutex.Close()
End Sub
End Class

HTH,
Greg

"Luis Mendes" <an*******@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Hello,

I want to make an aplication that runs only one time.

Let me explain better, each time I click on 'calculator' icon, it will open several 'calculators'.
What I want to do is to make a aplication that, if I click is icon it will open the aplication, if the aplication is already open it will 'bring it to
front' instead of open a new aplication.

Thank's in advance
Luis Mendes

Nov 20 '05 #3
The code I currently use is

Dim Processes() As Process
Processos = Process.GetProcessesByName("Taskfind")
If Processos.Length > 1 Then
End
'If any process with the same name is running, end the application
End If
Application.Run(FormToBeRun) 'If not, open the form

This code is in Sub Main.

Andre Nogueira

"Luis Mendes" <an*******@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Hello,

I want to make an aplication that runs only one time.

Let me explain better, each time I click on 'calculator' icon, it will open several 'calculators'.
What I want to do is to make a aplication that, if I click is icon it will open the aplication, if the aplication is already open it will 'bring it to
front' instead of open a new aplication.

Thank's in advance
Luis Mendes

Nov 20 '05 #4
* "=?Utf-8?B?THVpcyBNZW5kZXM=?=" <an*******@discussions.microsoft.com> scripsit:
I want to make an aplication that runs only one time.

Let me explain better, each time I click on 'calculator' icon, it will open several 'calculators'.

What I want to do is to make a aplication that, if I click is icon it will open the aplication, if the aplication is already open it will 'bring it to front' instead of open a new aplication.


<URL:http://www.pobox.com/~skeet/csharp/faq/#one.application.instance>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stuart A Yeates | last post by:
I'm trying to write a template that matches "*" but which has an if clause which if only executed once per type of element seen (where all elements of a type have the same name and namespace). The...
1
by: Jacob Jensen | last post by:
Hi I have a problem creating C++ code that is multiplatform compilable. My problem is using the "#pragma once" directive which can be used by microsoft Visual Studio pre-compiler but which gives...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
5
by: ShaunO | last post by:
BACKGROUND I have the following classes as part of a program that opens 3 Asynchronous Sockets. Each socket is in a separate instance of a wrapping class. 1x User Interface class 1x Client...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I have been using the Click Once deployment feature of VS2005 - very nice. I had IE6 at the time when I started using Click Once Deployment, and everything worked fine. But then my...
10
by: Lorenzo Di Gregorio | last post by:
Hello, I've been using Python for some DES simulations because we don't need full C speed and it's so much faster for writing models. During coding I find it handy to assign a variable *unless...
29
by: Neil | last post by:
Running a SQL 7 system on a Windows 2000 server using Access 2000 on client machines as a front end. System administrator currently reboots the server once a month. Yesterday we had some weird...
26
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? ...
5
by: raashid bhatt | last post by:
What is #pragma once used for and what is #WIN#@_LEN_AND_MEAN
4
by: Yonih | last post by:
Hey Yall, I am trying to incorporate a Once Per session Cookie that will expire once the browser is closed so some one who comes to my website will see my popup the first time her visits the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.