473,770 Members | 2,082 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 2246

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
8881
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
5989
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
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9432
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
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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
8891
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...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.