{oapdf_gg}
Five: robust call C # code (the actual consideration, can be placed on B / S system) completed Step 4 of the C # tests, careful readers may see that the problem of how to get a script that is running the results of the output, how to call the StartConvertData thread method of transmission parameters 1: transmission parameters, this can also be said to tell you a tutorial thread on how to pass method parameters, now talk about a program, a lot of such programs, I use a category, this type of initialization, and then call methods such as the implementation of the method of thread 2: get the script output, use the Process object to redirect the output, that is the direction of change in output, so that the script does not output to the console (MS-DOS window), but redirect the output to the C # program, and uses the asynchronous callback method thread to show the results of the script to run. add a new category, called type ToPdf using System; using System.Diagnostics; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Doc2Pdf ( public class ToPdf ( private string strWord = "";// here WORD document does not contain the path private string sPath = ""; public string sExecResult = ""; public bool bSuccess = false; public ToPdf (string sParamWord, string sParamPath) ( strWord = sParamWord; sPath = sParamPath; ) public void StartConvertPDF () ( Process proc = new Process (); proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.WorkingDirectory = sPath; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; //Redirect standard input proc.StartInfo.RedirectStandardOutput = true; //Redirect standard output proc.Start (); proc.StandardInput.WriteLine ( "cscript //nologo" + sPath + "ConvertDoc2PDF.js" + sPath + strWord + "" + sPath); proc.StandardInput.WriteLine ( "exit"); sExecResult = proc.StandardOutput.ReadToEnd ();// return to the implementation of the outcome of the script proc.WaitForExit (); proc.Close (); ) public void EndConvertPDF (System.IAsyncResult ar) //ar parameters must write is thread after the completion of the implementation of the callback function ( if (sExecResult.IndexOf ( "isuccess ")!=- 1) bSuccess = true; else if (sExecResult.IndexOf ( "isfail ")!=- 1) bSuccess = false; //if on the B / S system, you can write a database here is the success or failure of WEBService procedures with a database continuously to check that procedures are not on the WEBService Back to call function //if on the C / S system, the callback function can not be placed on class in order to form the outcome of the procedure call ) ) ) rewrite the original code in the button1_Click event private void button1_Click (object sender, System.EventArgs e) ( ToPdf my2Pdf = new ToPdf ( "test.doc", "c:\\"); ThreadStart thStartConvert = new ThreadStart (my2Pdf.StartConvertPDF); //asynchronous call to start the thread thStartConvert.BeginInvoke (new AsyncCallback (my2Pdf.EndConvertPDF), null); //Set the callback function asynchronous thread //If you need to convert a number of WORD, you can use the cycle //If it is B / S system can be on the ASPX code of this paragraph, combined with the non-client technology refresh display data continuously visit WEBService procedures to determine the PDF whether success or failure of the conversion ) |