473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Process.StandardOutput.ReadLine Blocks even with Threading

1
Hi

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
  1. Process p = new Process();
  2.  
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         Cache["Progress"] = "";
  6.  
  7.         System.Threading.Thread thrdDTS = new System.Threading.Thread(RunDTS);
  8.         thrdDTS.Start();
  9.  
  10.         System.Threading.Thread thrdProgress = new System.Threading.Thread(DTSProgress);
  11.         thrdProgress.Start();
  12.     }
  13.  
  14.     private void RunDTS()
  15.     {
  16.         System.Diagnostics.ProcessStartInfo oInfo = new System.Diagnostics.ProcessStartInfo("dtsrun", " /S xxx /U xxx /P xxx /N \"pkgDTSTest\"");
  17.         oInfo.UseShellExecute = false;
  18.         oInfo.ErrorDialog = false;
  19.         oInfo.CreateNoWindow = true;
  20.         oInfo.RedirectStandardOutput = true;        
  21.  
  22.         p.StartInfo = oInfo;
  23.         p.Start();
  24.  
  25.     }
  26.  
  27.     private void DTSProgress()
  28.     {
  29.         System.Threading.Thread.Sleep(2000);
  30.  
  31.         System.IO.StreamReader oReader2 = p.StandardOutput;        
  32.  
  33.         while (!p.HasExited)
  34.         {
  35.             string output;
  36.  
  37. //THIS IS THE LINE THAT BLOCKS
  38.             if ((output = oReader2.ReadLine()) == null)            
  39.                 output = "NULL";
  40.  
  41.             Cache["Progress"] += output + "<br />";            
  42.  
  43.             System.Threading.Thread.Sleep(200);
  44.         }
  45.  
  46.         oReader2.Close();
  47.     }
Is it possible that this behaviour results from trying to do this through a webpage? All the examples i have been looking at refer to using this approach from console applications or winforms.

Any help would be appreciated
Nov 23 '06 #1
0 2199

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mwazir | last post by:
Hi all, I have reposted this question from dotnet.general as I have been advised that this is a more appropriate forum for this question. Apologies for the repost. I have a process thats...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: Al Cohen | last post by:
I'll start by warning that I'm a newbie to C# (but I've been programming for 25 years), so I may just be doing something reallyreally dumb. I'm writing a C# wrapper for a command-line application...
1
by: JC | last post by:
I'm trying to create a GUI wrapper for dumpbin, and so I'm using the Process class to run the command-line application. The problem is that if I use Readline() to get the output from the...
2
by: palaga | last post by:
Hi I'm starting an external process that writes data to stdout, and I want to get back these data. So I use myProcess.StandardOutput (everything is correctly set, I can read the data). to read...
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
2
by: mwazir | last post by:
Hi all, I have a process thats starts in my application and only terminates when my application is terminated. I want to write the output and the errors of this process to a seperate log file....
5
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the...
11
by: Jon Davis | last post by:
Does anyone know why using System.Diagnostics.Process to "wrap" a console application does not always transmit the I/O, depending on what processes you're trying to "consume"? PowerShell, for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.