I'm trying to run a DTS package from a ASP.NET web page using System.Diagnostics.Process. This DTS takes up to 10 minutes to complete, during which, output is generated which i would like to trap and output to a client.
Having read a bit of literature about this, i realise that it is necessary to start a new thread to report on the progress of the process using StandardOutput. However, the first attempt to read from this stream causes the thread that is supposed to generating the progress output to block until the main process is complete, at which point the entire output is available.
The code i am using is this:
Expand|Select|Wrap|Line Numbers
- Process p = new Process();
- protected void Page_Load(object sender, EventArgs e)
- {
- Cache["Progress"] = "";
- System.Threading.Thread thrdDTS = new System.Threading.Thread(RunDTS);
- thrdDTS.Start();
- System.Threading.Thread thrdProgress = new System.Threading.Thread(DTSProgress);
- thrdProgress.Start();
- }
- private void RunDTS()
- {
- System.Diagnostics.ProcessStartInfo oInfo = new System.Diagnostics.ProcessStartInfo("dtsrun", " /S xxx /U xxx /P xxx /N \"pkgDTSTest\"");
- oInfo.UseShellExecute = false;
- oInfo.ErrorDialog = false;
- oInfo.CreateNoWindow = true;
- oInfo.RedirectStandardOutput = true;
- p.StartInfo = oInfo;
- p.Start();
- }
- private void DTSProgress()
- {
- System.Threading.Thread.Sleep(2000);
- System.IO.StreamReader oReader2 = p.StandardOutput;
- while (!p.HasExited)
- {
- string output;
- //THIS IS THE LINE THAT BLOCKS
- if ((output = oReader2.ReadLine()) == null)
- output = "NULL";
- Cache["Progress"] += output + "<br />";
- System.Threading.Thread.Sleep(200);
- }
- oReader2.Close();
- }
Any help would be appreciated