In VB 2005 checking making your application single instance has been made as easy as clicking a checkbox. And it even allows you to set the Focus to the already running instance without writing a single line of code.
Open Project Properties, and Select Application. Under Windows Application Framework properties check the "Make Single Instance Application" check box. Now if you build the project, your application will automatically become a single instance application.
And if you want to bring the already running instance to Foreground thats also easy. Trap the My.Application.StartupNextInstance event and set e.BringToForeground to true.Isn't it easy.VB Code:
Namespace My Partial Friend Class MyApplication Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, _ ByVal e As _ Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance e.BringToForeground = True End Sub End Class End Namespace
I have started loving VB 2005.![]()





Reply With Quote