|
-
May 17th, 2013, 06:07 PM
#1
Thread Starter
Member
[RESOLVED] making a vb.net app start 2 times
so Basically, i want my vb.net application to start 2 times, by itself, how to do that, should i use a timer ?
i have an other silly question, i want to remove the blue default icon of VB.net, to a default windows exe icon, how to do dat?
PLease help
-
May 20th, 2013, 08:41 AM
#2
Addicted Member
Re: making a vb.net app start 2 times
Changing the default icon was answered here: http://www.vbforums.com/showthread.p...(default-icon)
A timer would work to start your application multiple times.
-
May 20th, 2013, 08:53 AM
#3
Re: making a vb.net app start 2 times
The issue you have when running any sort of code to open your app multiple times is that, it's going to run in the second application too. What I would do is in you form_load event, check if there is an instance of your application, if not then create a new instance, if so then do nothing:
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Get all instances of WindowsApplication1
'If your application name is something else, then change the "WindowsApplication1" to it's name
Dim my_application() As Process = Process.GetProcessesByName("WindowsApplication1")
'Check if there is only 1 instance of my application
If my_application.Count <= 0 Then
'Create new instance
Dim new_form As New Form1
new_form.Show()
new_form.Focus()
End If
End Sub
But even in this example, it will open multiple instances of Form1 because it keeps running until the my_application.Count is greater than 0. So perhaps someone else could shed some light.
-
May 20th, 2013, 09:08 AM
#4
Re: making a vb.net app start 2 times
I'd create a bootstrap program... when it starts up, it launches the "real" app twice then shuts down... A console app with two calls to process.Start should be sufficient.
-tg
-
May 20th, 2013, 09:11 AM
#5
Re: making a vb.net app start 2 times
dday9 has the correct idea, however since you're using VS2008 there is no Count method on the array returned by GetProcessByName since that is an extension method introduced in VS2010. Hard coding in the process name is also not really recommended, you can use a function such as this:
Code:
Public Function PreviousInstanceCount() As Integer
Return Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length - 1
End Function
You can call this from your Form_Load event and check if the return value is 0 then you need to launch your application a second time.
Code:
If PreviousInstanceCount = 0 Then
Process.Start(Process.GetCurrentProcess.MainModule.FileName)
End If
Note that this will not work while you run the application in debug mode from Visual Studio but it will work when you launch the compiled application (or start it with full compile, Ctrl+F5)
-
May 20th, 2013, 11:58 AM
#6
Re: making a vb.net app start 2 times
Could there not be any conflict if another application had the same name?
vb Code:
Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim instance As Boolean Dim mutex As New Threading.Mutex(False, "Local\ApplicationName", instance) If instance Then Process.Start(Process.GetCurrentProcess.MainModule.FileName) End If End Sub End Class
-
May 20th, 2013, 12:49 PM
#7
Thread Starter
Member
Re: making a vb.net app start 2 times
Thanks guys that really helped !
-
May 20th, 2013, 01:11 PM
#8
Re: making a vb.net app start 2 times
Please mark your thread resolved from the tools menu.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|