Click here to Skip to main content
15,901,666 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Detecting Windows Events Pin
John Kuhn22-May-03 7:58
John Kuhn22-May-03 7:58 
GeneralLoops HELP Pin
bamnet22-May-03 5:26
bamnet22-May-03 5:26 
GeneralRe: Loops HELP Pin
John Kuhn22-May-03 7:25
John Kuhn22-May-03 7:25 
GeneralRunning one Instance of EXE Pin
pradipta22-May-03 3:03
pradipta22-May-03 3:03 
GeneralRe: Running one Instance of EXE Pin
Giles22-May-03 3:45
Giles22-May-03 3:45 
GeneralRe: Running one Instance of EXE Pin
CBoland22-May-03 4:07
CBoland22-May-03 4:07 
GeneralRe: Running one Instance of EXE Pin
Giles22-May-03 7:34
Giles22-May-03 7:34 
GeneralRe: Running one Instance of EXE Pin
CBoland22-May-03 4:06
CBoland22-May-03 4:06 
Interesting questions! For the single app instance, try using a Mutex:

Sub Main()

Dim M1 As System.Threading.Mutex
Dim createdNew As Boolean = False
M1 = New System.Threading.Mutex(True, "MyUniqueMutexName", createdNew)

If createdNew = False Then
MsgBox("Other process is running")
Return
End If

Application.Run(New Form1())

End Sub

For single form intance, this is a bit of a hack, but it works. The problem with maintaining a member-level ref to a form occurs after the form has been closed. At this point the form is disposed, but we have no way of determining the disposed state by examining the ref (that I know of). My hack catches an ObjectDisposedException as a way of determining the disposed state. You could also subclass Form, override Dispose(bool) and provide an IsDisposed property.

' Member-level reference
Private _Form2 As Form2

...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If _Form2 Is Nothing Then _Form2 = New Form2()

Try
_Form2.Show()
_Form2.BringToFront()
Catch ex As ObjectDisposedException
_Form2 = New Form2()
_Form2.Show()
End Try

End Sub
GeneralRe: Running one Instance of EXE Pin
pradipta22-May-03 20:09
pradipta22-May-03 20:09 
GeneralRe: Running one Instance of EXE Pin
GrindAZ22-May-03 6:05
GrindAZ22-May-03 6:05 
GeneralShort to Long fileName in VB6 and WinNT Pin
Alberto Bar-Noy22-May-03 2:12
Alberto Bar-Noy22-May-03 2:12 
QuestionHow do I set the “Comment” attribute of a file or folder using VB script ? Pin
Serge Krynine21-May-03 21:56
Serge Krynine21-May-03 21:56 
QuestionVb.net: how add an column (field) into a table in Access database? Pin
gline21-May-03 20:26
gline21-May-03 20:26 
GeneralCreating A Windows Service...HELP! Pin
GrindAZ21-May-03 7:23
GrindAZ21-May-03 7:23 
GeneralRe: Creating A Windows Service...HELP! Pin
John Kuhn21-May-03 12:39
John Kuhn21-May-03 12:39 
GeneralRe: Creating A Windows Service...HELP! Pin
Dave Kreskowiak22-May-03 4:40
mveDave Kreskowiak22-May-03 4:40 
GeneralRe: Creating A Windows Service...HELP! Pin
GrindAZ22-May-03 5:57
GrindAZ22-May-03 5:57 
QuestionAbout pop AD??? Pin
mgj20-May-03 15:53
mgj20-May-03 15:53 
QuestionfdmakkHow can I use the vb ,make a add-in for VB? Pin
mgj20-May-03 15:46
mgj20-May-03 15:46 
QuestionHow to implement component class in vb Pin
TianYang20-May-03 15:27
TianYang20-May-03 15:27 
Generalvarible in shell Pin
bamnet20-May-03 11:16
bamnet20-May-03 11:16 
GeneralRe: varible in shell Pin
Ray Cassick20-May-03 12:10
Ray Cassick20-May-03 12:10 
GeneralRe: varible in shell Pin
Nick Seng20-May-03 15:57
Nick Seng20-May-03 15:57 
GeneralAbout custom-drawn linklabel controls Pin
Chopper20-May-03 5:02
Chopper20-May-03 5:02 
GeneralRe: About custom-drawn linklabel controls Pin
Ray Cassick20-May-03 6:15
Ray Cassick20-May-03 6:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.