'My' is available throughout the Framework. The way that VB does it is to
auto-generate this (in Application.Designer.vb) -
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make
changes,
' or if you encounter build errors in this file, go to the Project
Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMo
de.Windows)
Me.IsSingleInstance = true
Me.EnableVisualStyles = false
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle =
Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormC
loses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.iViewHelper.Form1
End Sub
End Class
End Namespace
- and a dummy namespace My (in ApplicationEvents.vb) points to useful events
-
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
End Class
End Namespace
So, I can tweak .IsSingleInstance and .StartupNextInstance appropriately via
my configuration routines and some saved Settings; I'm just asking if there
are other methods, and what the pros and cons might be.
And - WinForms, not WPF (as the subject says).
_____
Ian Thomas
Victoria Park, Western Australia
_____
From: [email protected] [mailto:[email protected]]
On Behalf Of Ian Thomas
Sent: Thursday, December 29, 2011 9:48 PM
To: [email protected]
Subject: Switching between single- and multiple-instance (WinForms)
Visual Basic projects can be very easily made single instance (Make Single
Instance Application property for the project), but I'd like a simple way to
change single instance behaviour to multiple-instance (in the same way that
many text editors allow it as a configuration - eg, TextPad).
What is recommended? (either language)
_____
Ian Thomas
Victoria Park, Western Australia