Restricting only one copy to run

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Hi,

My app now has the ability to open a .chm help file to help the user learn how to use my app.

I use process.start to achieve this but notice a new window opens with every click which is rather naff!

I have tried to track the process and identify if one is running with little success.

I know nothing about threading....the topic makes me hide under my rock:confused:

Do I have to enter this realm to achieve the results I want?

Thanks for any help forthcoming
 
so you want only 1 copy of your program to run at a time? or only one copy of the help file to be open at a time?

For the help file, use:
VB.NET:
Help.ShowHelp(Me, "HelpFile.chm")

for the one instance of the program:
VB.NET:
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If PrevInstance() = True Then Me.Close()
    End Sub


    Private Function PrevInstance() As Boolean
        If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
 
Kool, the help restriction works a treat thanks ;)

Handy too to see how to restrict one copy of the application to run also, thanks again ;)
 
Mmm cannot get the app version to run, does not like ti Ubound command which is old vb which I don't use and can't get the .net way to work?

any tips?:confused:
 
i guess UBound is used there, i'll make a .net one:
VB.NET:
    Private Function PrevInstance() As Boolean
        If CInt(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName).GetUpperBound(0)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
 
I'm using VB2005 and compact framework. It appears that the GetProcessesByName function is not supported. Do you know haw to prevent multiple instances of a program running on the compact framework?
 
Thread was moved to CF forum section.
 
Back
Top