Shared Instance of MS Word?

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

My boss indicated he was pleased with the reports that were being generated
in MS Word by me and that made me happy.

However he also told me he wants the wait eliminated for Word to start up. I
explained Word takes a while to start and that is why. He indicated I should
find a way for it to start in the beginning of hte program so users would
not have to wait to get their reports done. (In other words he would prefer
they wait at startup)

So here is my issue:

I need to find a way to make an instance of Word accessible to be called at
all times. The only catch is that those users who do not have the word
version I require (Word 2000 or above) the way it stands now are able to use
the rest of the software that does not require Word.

The way I am doing it now is to start the instance at the time of the report
request which is why it is taking so long to start.

Does anyone have ideas on this?
 
something i do sometimes...


create a class that you instantiate in the beginning of your program
that class creates a thread which is started at the end of your constructor
that thread creates the word instance

then you have a readonly property in that class to get the word instance
in that property you check if word instance is already set, otherwise you
wait for your thread

so: if user is a quick user that needs the word instance very fast he will
still have to wait...
for a normal user no waiting...
and because of the multithreading you wont see much difference at startup...
your form will not stop responding...

one more remark: don't forget to close your word application when your
program stops
(implement IDisposable ?)


hope this helps

Dominique
 
Very much.

Would you be willing to show a code sample or a link for a tutorial on this?

One other thing. Correct me if I am wrong but wouldn't a user who did not
have Word 2000 or above if word was oeprating globally it would throw an
exception wouldnt it?
 
At the start of your program, use CreateObject to create a new instance of
Word and assign it to an object variable. Then you use that object variable
whenever required.
 
not tested:


Public Class WordGetter
Implements IDisposable

Private _cantCreateWordException As Exception = Nothing
Private _word As Object = Nothing
Private _myThread As Thread

Public Sub New()
_myThread = New Thread(AddressOf CreateWordInstance)
_myThread.Start()
End Sub

Private Sub CreateWordInstance()
Try
Dim tempWord As Object
'
'do stuff to fill in tempWord
'
_word = tempWord
Catch e As Exception
_cantCreateWordException = e
End Try
End Sub

Public ReadOnly Property Word() As Object
Get
If (_word Is Nothing) Then
If (Not _cantCreateWordException Is Nothing) Then
Throw _cantCreateWordException
End If
_myThread.Join()
End If
Return _word
End Get
End Property

Public Sub Dispose() Implements System.IDisposable.Dispose
'
'do stuff to correctly unload word
'
End Sub
End Class
 
If I do that, if they do not have Word 2000 or above on their computer will
it bomb?
 
For some reason my newsserver is delaying my responses. I am very sorry
about this.

If you see this please go to the thread RPC Server Error......

I already figured out the share issue.
 
Back
Top