{oapdf_gg}
VI: the preparation of a more robust C # calling code (the actual consideration of the services available on the WINDOWS program) actual use, due to PDF conversion at very high occupancy rate of CPU, consider the conversion at the same time only a WORD document, asynchronous thread to give up the use of callback functions, WINDOWS consider a service process. write a function CheckData2Convert (), continue to check there is no conversion of the WORD document and use of recycled ToPdf class call methods of the implementation of the conversion StartConvertPDF //the following is given, the Pan-code, the user according to their own needs, can be completed //bool bStart for global variables to control the entry and exit cycle //example: 18:30 to start checking and conversion, then 18:30 am, bStart = true; and start the conversion thread //6:30 to stop the conversion thread, bStart = fasle; private void CheckData2Convert () ( //check the specified directory does not convert the WORD document, you can also check the database there is no record of the WORD document conversion string sPath = System.Threading.Thread.GetDomain (). BaseDirectory; //the current path while (bStart) ( int iFileCount = CheckWord (); //CheckWord is a process, not to check the current conversion of the WORD document, return the number of documents does not convert the method from the code reader I have written < / p> for (int i = 0; i ( string sWord = GetWordFileName (i) //GetWordFileName is a process, return to the path of a WORD document with the name of the method code from the reader I have written //ToPdf category StartConvertPDF () method without using the WORD file name path ToPdf my2Pdf = new ToPdf (sWord, sPath); my2Pdf.StartConvertPDF (); if (my2Pdf.sExecResult.IndexOf ( "isuccess ")!=- 1) ( //success, writing the log, or a database write-back ) else if (my2Pdf.sExecResult.IndexOf ( "isfail ")!=- 1) ( //failure to write the log, or a database write-back ) ) if (! bStart) break; Thread.Sleep (1000); ) ) the beginning and then in the service case, start the thread protected override void OnStart (string [] args) ( //can use a timer to start to check the start time, the time comes, the beginning of the implementation of threads on here the beginning of the implementation of thread can be the beginning of regular events in //end timer can use a check to the end of time, the time comes, the end of threads, thread the end of the code can be placed on the end of regular events //NOTE: should not use the timer component, rather than the Windows timer FORMS of //the class timer named System.Timers.Timer, never made a mistake, otherwise the implementation will not be normal bStart = true; Thread thConvert = new Thread (new ThreadStart (StartConvertData)); thConvert.Start (); ) and then in the service end of the incident, set up to stop the logo thread bStart = false protected override void OnStop () ( bStart = false; //why the Department did not stop at this thread, bearing in mind that now thread WORD document is converted, but not ended, it only set up to stop labeling, conversion is complete, line Cheng is also the implementation of an end. ) |