Waiting for a process to Finish (Threading)

  • Thread starter Thread starter Dean Richardson
  • Start date Start date
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
 
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
 
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
 
Would this not work for you?

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