Click to See Complete Forum and Search --> : Run Once


Curt
April 8th, 2002, 11:31 AM
In Vb6 I set my startup routine to Main and
add..



Sub Main()


If App.PrevInstance = true then Exit Sub
'............

Load frmMain

End Sub





How is this done in vb.net?

Curt

softweng
April 9th, 2002, 11:39 AM
Try This:

option Strict on
option Explicit on
Imports System.Diagnostics.Process
public Class Form1
Inherits System.Windows.Forms.Form

private Sub Form1_Load(byval eventSender as System.Object, byval eventArgs as System.EventArgs) Handles MyBase.Load

If (UBound(GetProcessesByName(GetCurrentProcess.ProcessName)) > 0) then Exit Sub

End Sub
End Class




Kris
Software Engineer
Phoenix,AZ

Curt
April 9th, 2002, 12:27 PM
thank you,
it works very well.

Curt

vchapran
April 28th, 2002, 02:57 PM
I'm trying to use this approach with MDI application. It starts with Splash screen, then Splash unloads and MDI is loading and stays there. I added your code in MDI_Load and it doesn't work.
I understand it this way:
(UBound(GetProcessesByName(GetCurrentProcess.ProcessName)) > 0) is true for my child window only, so it doesn't stop MDI loading. But it does stop Child loading.
So, your code can work with simplest scenario only (one form in project). What changes should I make to use it as it was with App.PrevInstance in VB6?
Thank you
Vlad

vchapran
April 28th, 2002, 03:29 PM
I found the way to handle it, at least for my situation.
If you replace Exit Sub with Me.Close it won't allow to load MDI. Since all forms loaded from the first form (it's not always MDI) will be unloaded when you unload the first one, it looks like it's going to work.
Correct me if I'm wrong
Thank you
Vlad