473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Referencing application though VB.NET

I am currently developing an application in VB.NET that uses the Microstation's object model via COM Interop.

I have a problem regarding multiple instances of the Microstation application (ustation.exe) and calling the COM object in multiple forms in my application.

The Microstation Application object is demnsioned in Common.mod

Public oMSTN As MicroStationDGN.Application
My application is entered in StartUp.mod and there is a routine that determines if Microstation is already running or not. Different forms load depending on if the user already has an instance if Microstation running or not.
##############################################
# CODE EXECUTED IN STARTUP.MOD #
# TO START MICROSTATION IF IT ISN'T #
# ALREADY RUNNING #
# #
# oMSTN DIMENSIONED IN COMMON.MOD #
# Public oMSTN As Application #
##############################################
Private Sub CheckForProject()
If IsProcessExecuting("ustation") = False Then
projectForm = New frmProj
projectForm.ShowDialog()
Else
'process is executing so get the project
'configuration file currently selected
'and set project ID from database

oMSTN = New MicrostationDGN.Application
sConfigName = oMSTN.ActiveWorkspace.ConfigurationVariableValue(" _USTN_PROJECTNAME")

lProj_ID = GetProjIDFromDb(sConfigName)
End If
End Sub

If Microstation is running then a new instance of oMSTN must be started so that my application can read a microstation configuration variable. That works fine, howver, when other forms load I don't know how to reference the same instance of oMSTN. Starting new instances of oMSTN in each form simply starts and extra instance of ustation.exe running in task manager.

How do I start a call this code once "oMSTN = New MicrostationDGN.Application" in my startup module and then use oMSTN in every form that loads after that?

Thanks in advance

Russ
Nov 21 '05 #1
7 5780
How stupid of me. I'll try this but may need to call on you for some more
help.

Thanks

Russ
"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:uG**************@TK2MSFTNGP15.phx.gbl...
http://c2.com/cgi/wiki?VisualBasicSingleton

HTH Jonas

Nov 21 '05 #3
Even better (VB.Net specific):
http://www.ondotnet.com/pub/a/dotnet...singleton.html
Nov 21 '05 #4
Thanks for this. I'm starting to understand and I had a go but I was still
struggling a little. I couldn't access to object model of Microstation
through this singleton class that I built. So that I can understand this I
am starting with a basic example, but what might that class look like if it
were to be added to the following simple app?

Russ
Public Class Form1
Inherits System.Windows.Forms.Form

Private oWinWord As Word.Application

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Word isn't running so start it
oWinWord = New Word.Application
oWinWord.Visible = True

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & "
documents open"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
oWinWord = New Word.Application

oWinWord.Documents.Add()

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & "
documents open"
End Sub

End Class
"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
Even better (VB.Net specific):
http://www.ondotnet.com/pub/a/dotnet...singleton.html

Nov 21 '05 #5
Well, the purpose of the singleton pattern is to make sure that you are
allways working with only one instance of a class.
I thought this was what you wanted. Applied to your word example it would be
something like this.

public class WordAppSingleton

private shared _myInstance as Word.Application

public shared function GetInstance() as Word.Application
if _myInstance is nothing
_myInstance = New Word.Application 'TODO: Add check if App is
allready running
end if

return _myInstance
end function

end class

Now, if you want to work with the instance of your word application you
would use the shared function WordAppSingleton.GetInstance() to get it, like
this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Word isn't running so start it
dim oWinWord as Word.Application = WordAppSingleton.GetInstance()
oWinWord.Visible = True

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & "
documents open"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
dim oWinWord as Word.Application = WordAppSingleton.GetInstance()

oWinWord.Documents.Add()

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & "
documents open"
End Sub

So you won't be needing a global oWinWord variable anymore. Use local
variables and WordAppSingleton.GetInstance().
Is this what you need?
Nov 21 '05 #6
That's very clear, thank you so much
"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
Well, the purpose of the singleton pattern is to make sure that you are
allways working with only one instance of a class.
I thought this was what you wanted. Applied to your word example it would be something like this.

public class WordAppSingleton

private shared _myInstance as Word.Application

public shared function GetInstance() as Word.Application
if _myInstance is nothing
_myInstance = New Word.Application 'TODO: Add check if App is
allready running
end if

return _myInstance
end function

end class

Now, if you want to work with the instance of your word application you
would use the shared function WordAppSingleton.GetInstance() to get it, like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Word isn't running so start it
dim oWinWord as Word.Application = WordAppSingleton.GetInstance()
oWinWord.Visible = True

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & " documents open"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
dim oWinWord as Word.Application = WordAppSingleton.GetInstance()

oWinWord.Documents.Add()

Me.Label1.Text = "There are " & CStr(oWinWord.Documents.Count) & " documents open"
End Sub

So you won't be needing a global oWinWord variable anymore. Use local
variables and WordAppSingleton.GetInstance().
Is this what you need?

Nov 21 '05 #7
One last thing though:

When you use the singleton pattern with an object that holds a reference to
an external Application (like word or microstation) you should
allways have in mind, that a user may shut down the external program
manually. Better check if the app you're working with is still running in
the
GetInstance() Method (which can be a HPITA if you're working with Excel et
al).

"Russ Green" <ru**@NO-SPAMrussgreen.net> schrieb im Newsbeitrag
news:eD**************@TK2MSFTNGP10.phx.gbl...
That's very clear, thank you so much

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jon | last post by:
I have 3 VB.net executables that reference the same 3 VB.Net DLLs. How is the best way to distribute the EXEs without putting 3 copies of of DLL on a user's machine. I looked into Private...
4
by: Jelmer | last post by:
Hi I've been trying to create an addin similar to Find & Replace from Rick Fisher that looks thru your tables / queries / forms / modules etc.. for a reference to a string and optionally let's you...
5
by: Nice Chap | last post by:
I know this is NOT possible in Visual Studio but some how Sharp Develop can do it !! any thoughts...
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
9
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
4
by: steve_barker333 | last post by:
Hi guys! I keep getting the following error reported by VS 2005 in my ASP.NET 2.0 web project: "The type or namespace name 'MainPages_XXX' could not be found (are you missing a using...
7
by: Wiebe Tijsma | last post by:
Hi, I'm running a web application application using the Microsoft.Interop.Security.AzRoles version 1.2.0.0 in the GAC. After an upgrade to Vista, I also have a version 2.0.0.0 in the GAC. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.