By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

Referencing a running instance of the assembly

P: n/a
I have a VB.Net application that can be executed with parameters.
If parameters are received, the I execute a function that will open a form
within the application.
On top of that, I'd like to detect if there's another instance of this
application already running, so I don't have to start another one, but I need
to execute that function that opens a form (on the executing instance), and
here's where I'm stuck.

This is the code:
<System.STAThread()> _
Public Shared Sub Main()
Dim oParam As Object
oParam = Environment.GetCommandLineArgs()

If oParam.length > 1 Then
If
Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName).Length > 1
Then
'-- Another instance is already running
Dim o, asm As Object
o =
Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName)(1)

'-- NOT SURE HOW TO REFERENCE "EXECUTE" ON THE OTHER INSTANCE...
o.Execute(oParam(1))
o = Nothing
Else
'-- There's no other instance running
System.Windows.Forms.Application.EnableVisualStyle s()
System.Windows.Forms.Application.Run(New frmMain(oParam(1)))
End If
Else
'-- NO parameters
System.Windows.Forms.Application.EnableVisualStyle s()
System.Windows.Forms.Application.Run(New frmMain)
End If
oParam = Nothing
End Sub 'Main

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.