473,797 Members | 3,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StandardInput / StandardOutput - C# Buffer

Hi,

I have two threads in my application, one that decodes audio to a
stream and one that encodes a stream to a file.

If I run them as two seperate processes I can pipe the output from one
to the input of the other - and all is well. The writes to standard
output are obviously synchronous, so the decoding occurs at the rate at
which the encoder can process...

How do I replicate this with two threads in one process? I guess what
I want is a single frame FIFO queue or something similar. Does there
exist something in the framework to achieve this, or do I have to roll
my own?

thanks in advance

Aug 26 '06 #1
1 2917
no***********@g mail.com wrote:
I have two threads in my application, one that decodes audio to a
stream and one that encodes a stream to a file.

If I run them as two seperate processes I can pipe the output from one
to the input of the other - and all is well. The writes to standard
output are obviously synchronous, so the decoding occurs at the rate at
which the encoder can process...

How do I replicate this with two threads in one process? I guess what
I want is a single frame FIFO queue or something similar. Does there
exist something in the framework to achieve this, or do I have to roll
my own?
Maybe this can give you some ideas:

using System;
using System.IO;
using System.Net;
using System.Net.Sock ets;
using System.Threadin g;

namespace E
{
public class MainClass
{
private const int PORT = 12345;
private static TextWriter savout;
private static TextReader savin;
private static void StartPipeOut()
{
TcpListener list = new TcpListener(IPA ddress.Any, PORT);
list.Start();
TcpClient cli = list.AcceptTcpC lient();
TextWriter sw = new StreamWriter(cl i.GetStream());
savout = Console.Out;
Console.SetOut( sw);
}
private static void EndPipeOut()
{
Console.Out.Clo se();
Console.SetOut( savout);
}
private static void StartPipeIn()
{
Thread.Sleep(0) ;
TcpClient cli = new TcpClient("loca lhost", PORT);
TextReader sr = new StreamReader(cl i.GetStream());
savin = Console.In;
Console.SetIn(s r);
}
private static void EndPipeIn()
{
Console.In.Clos e();
Console.SetIn(s avin);
}
public static void First()
{
StartPipeOut();
int n = 0;
for(int i = 0; i < 100000; i++)
{
Console.WriteLi ne("This is a test");
n++;
}
EndPipeOut();
Console.WriteLi ne("Wrote " + n);
}
public static void Second()
{
StartPipeIn();
int n = 0;
string line;
while((line = Console.ReadLin e()) != null)
{
n++;
}
EndPipeIn();
Console.WriteLi ne("Read " + n);
}
public static void Main(string[] args)
{
Thread first = new Thread(new ThreadStart(Fir st));
first.Start();
Thread second = new Thread(new ThreadStart(Sec ond));
second.Start();
first.Join();
second.Join();
Console.ReadLin e();
}
}
}

Arne

PS: Sorry for all the static but I did not want to spend time
inventig some classes.
Aug 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
412
by: John Lewin | last post by:
I've recently discovered the value of using existing console applications in managed .net apps. Unfortunately, I've stumbled into a problem with a particular console application that check's crc info on CDs. Using either the StandardError or StandardOutput streams read, readline or peek methods causes an immediate block that doesn't release until the console app finishes it's business. I want to launch this console app and update my UI to...
2
3391
by: dansan | last post by:
I have been tryning to make some of our C# programs talk to some perl programs. These perl jewels output in binary. I have been trying to use Process.StandardOutput to read the output from the perl programs. I am able to read the output if it is ASCII (or some char of some sort). But the issues comes when it is binary info. I have tried to use StandardOutput.BaseStream, which returns a Stream to then read the bytes out of that...
2
3185
by: Ivan Lam | last post by:
Hi all, Thanks for reading my post!!! I am facing a problem that I cannot redirect StandartOutput and StandardInput at the same time without closing the executive. Actually, I have a console application named "etm.exe", I would like to call it in my .net (VC) application. What I want to do is when the user type some command in my .net application, I redirect this command
1
11638
by: Panagiotis | last post by:
Hi everyone, this is what I want to do in C#: 1) start a Cygwin Bash Shell 2) send the Shell a command, for example "ls -l" 3) capture all the output of the command The code below seems to work when I there isn't alot of output to capture, but when the output increases, the code will freeze.
4
5289
by: [ripper] | last post by:
Hello, I'm building a software to interface with an .exe that will parse a text file (a lex program build in cygwin that works great when it's executed on it's own). The OutputXML is more than 150 000 characters and the software always bugs at the 20479 character, it just seems to hang and nothing happens. If I try with 20 000 characters it works great. Is there any size limitation ? If so is there anyway to get passed this
0
1473
by: SMichal | last post by:
Hi, I've got this exception in my code. I'm starting new process with Redirection of standart input. As you cann see, I'm using log4net for logging the input stream... What does this Exception meen ? How can I fix it ? StringBuilder args1 = new StringBuilder(); args1.Append("-n" + localhost + " -u" + userName + " -p" + password);
2
7671
by: nautonnier | last post by:
Hello, I have a C# app that spawns several processes each containing a console app written by another developer in C++. The console app was written first to be just like a console app: it starts, you type a command it does a command and returns a message. I thought I would be able to consume it in my C# app by using the Process.StandardInput in conjunction with the Process.StartInfo.RedirectStandardOutput. The output works fine and I...
6
12852
by: Ole | last post by:
Hi, I'm running a command line process from my C# application trying to catch the output messages from the process into a textbox in my windows form. But the text doesn't update (the ReadLine doesn't return) until the process exits??? Any help is highly appreciated! The code is like this: Process myProcess = new Process(); myProcess.StartInfo.FileName = Application.StartupPath + "\\myCmdLine.exe";
0
3020
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi I'm using vs2005, .net 2 for windows application. The application I started using System.Diagnostics.Process is having a "listFiles.StandardOutput" buffer size problem. I was wondering where and how can I adjust the buffer size problem. I don't want to be limited to a set buffer size, is that possible? thank you. public static int GetNisFile(System.Diagnostics.ProcessStartInfo psi, ref DataTable dtAccounts, ref...
1
2492
by: Dv | last post by:
When our application is launched from Dos console, we need to print some message to the console. I attached our application to the console using AttachConsole(ATTACH_PARENT_PROCESS), and then call Console.WriteLine(...) to print some messages there. Everything works fine, except that after the message has been printed, it'll require user to press any key exit from there. So, I'd like to insert a key stroke to the StandardInput...
0
9685
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
10469
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
10246
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...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
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
9066
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
7560
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
5459
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...
3
2934
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.