Link to home
Start Free TrialLog in
Avatar of polynominal
polynominal

asked on

Adding a timer to the code

I have the following code below which is part of the code I am using which interprets an image field in a database which contains binary data and outputs it in a folder on a directory in rtf format.

The folder can contain up to 10 to 30 different documents a day.

The code below opens up the documents in word and prints them out

object oMissing = System.Reflection.Missing.Value;
object oFalse = false;
object oTrue = true;
                   
//create word
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oWord.ActivePrinter = @"\\printer name";

//document
object file = Filename;
oDoc = oWord.Documents.Add(ref file, ref oMissing, ref oMissing, ref oMissing);

//print it
object xcopies = 1;
oDoc.PrintOut(ref oFalse, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref xcopies, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oFalse, ref oMissing, ref oMissing);

I want to add a timer to this, but I am not sure how to do it and whereabouts in the code it should be placed. The timer should work as follows, one docmunets is printed out and instead of instantly opening up and printing the next document add a 30 second delay before printing and do this for every document contained in the folder.

Can anybody help

Poly
Avatar of AlexFM
AlexFM

Thread.CurrentThread.Sleep(30000);

This line delays current thread for 30 seconds.
Avatar of polynominal

ASKER

Thanks I get the error message Type or namespace thread could not be found
Add - using System.Threading - on the top.
Whenever you get this "Type or namespace thread could not be found" error, search for the class name in msdn and see what namespace is required for that class.
e.g.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemthreadingthreadclasstopic.asp
here you can see System.Threading is required for Thread class.
Thanks for the answers. unfortunately msdn library is blocked at work so I cant see it
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial