473,785 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.Standar dOutput.ReadLin e Blocks even with Threading

1 New Member
Hi

I'm trying to run a DTS package from a ASP.NET web page using System.Diagnost ics.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 2248

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

Similar topics

2
2263
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 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. In order to do this, I spawned two threads.
18
4893
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
3
10408
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 (pscp.exe, a secure file-copy app that's part of the excellent PuTTY SSH package). Getting pscp.exe to run properly was a piece of cake using the System.Diagnostics.Process class. The thing that I can't get to work is the ability to read...
1
8884
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 commandline app, it will hang when it comes to the command-prompt (there's no return to send it to readline). Here's the code: public bool RunCommands(string cmds, ArrayList files) {
2
1616
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 data, I use myProcess.StandardOutput.ReadLine( ). (the data is text). The doc says that if there is no more data available, the function ReadLine return null.
1
5991
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 am executing the find.exe program. The application works perfectly in the development environment. As soon as I execute the compiled program and start the find process I get an "Application Error". The error states that the instruction...
2
2282
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. In order to do this, I spawned two threads. My code looks something like this ' Starting the process oProcessStartInfo = New ProcessStartInfo()
5
3458
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 "notes" not being the issue). Beginning with... Dim objProcess As Process Dim objProcessStartInfo As New ProcessStartInfo
11
11964
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 example, does not seem to process any I/O through the Process object. I know that in the case of PowerShell there are better ways to "wrap" the console by directly interfacing with the assemblies of System.Management.Automation or some similarly...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.