Waiting for a process to Finish (Threading)

D

Dean Richardson

Hello,

I have having issues with threading. Below is the code I am running:


'Prints the word doc
myWordApp.ActivePrinter = cboPrintList.SelectedItem


myWordApp.PrintOut()


'Sets the default printer back
myWordApp.ActivePrinter = strDefaultPrinter


'Pauses until the word document is printed
System.Threading.Thread.Sleep(2000)


'Closes the word document
myWordApp.Quit(False)


The issue is that the word document is still printing in word as the
Word Application closes, so the document never prints.


Is there a way to have quit word once the printing has finished by
using threads. I am quite new to threading, so I'm probably missing
something obvious (or not).


Many Thanks in Advance,
Dean
 
R

rowe_newsgroups

Hello,

I have having issues with threading. Below is the code I am running:

'Prints the word doc
myWordApp.ActivePrinter = cboPrintList.SelectedItem

myWordApp.PrintOut()

'Sets the default printer back
myWordApp.ActivePrinter = strDefaultPrinter

'Pauses until the word document is printed
System.Threading.Thread.Sleep(2000)

'Closes the word document
myWordApp.Quit(False)

The issue is that the word document is still printing in word as the
Word Application closes, so the document never prints.

Is there a way to have quit word once the printing has finished by
using threads. I am quite new to threading, so I'm probably missing
something obvious (or not).

Many Thanks in Advance,
Dean

I don't think Threading will solve the problem, as the thread will not
know when printing has finished - which is what the problem seems to
be. It might be possible to start a new thread to do the work, set
IsBackground = False and give it a much larger Sleep timeout that will
always account for the document being spooled before the thread exits.

Also, I not sure if the Office PIA's available from Microsoft have the
capabilities to better monitor print capabilities in Word or not - but
it may be worth checking out.

Thanks,

Seth Rowe
 
D

Dean Richardson

I don't think Threading will solve the problem, as the thread will not
know when printing has finished - which is what the problem seems to
be. It might be possible to start a new thread to do the work, set
IsBackground = False and give it a much larger Sleep timeout that will
always account for the document being spooled before the thread exits.

Also, I not sure if the Office PIA's available from Microsoft have the
capabilities to better monitor print capabilities in Word or not - but
it may be worth checking out.

Thanks,

Seth Rowe- Hide quoted text -

- Show quoted text -

Thanks for that. I ended up having a sleep method setup so that it
waits for 5000 milliseconds before running any further and its done
the job.

Thanks again,
Dean
 
G

Guest

Would this not work for you?

Do While myWordApp.BackgroundPrintingStatus
System.Windows.Forms.Application.DoEvents()
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top