473,406 Members | 2,208 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,406 software developers and data experts.

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 2891
no***********@gmail.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.Sockets;
using System.Threading;

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(IPAddress.Any, PORT);
list.Start();
TcpClient cli = list.AcceptTcpClient();
TextWriter sw = new StreamWriter(cli.GetStream());
savout = Console.Out;
Console.SetOut(sw);
}
private static void EndPipeOut()
{
Console.Out.Close();
Console.SetOut(savout);
}
private static void StartPipeIn()
{
Thread.Sleep(0);
TcpClient cli = new TcpClient("localhost", PORT);
TextReader sr = new StreamReader(cli.GetStream());
savin = Console.In;
Console.SetIn(sr);
}
private static void EndPipeIn()
{
Console.In.Close();
Console.SetIn(savin);
}
public static void First()
{
StartPipeOut();
int n = 0;
for(int i = 0; i < 100000; i++)
{
Console.WriteLine("This is a test");
n++;
}
EndPipeOut();
Console.WriteLine("Wrote " + n);
}
public static void Second()
{
StartPipeIn();
int n = 0;
string line;
while((line = Console.ReadLine()) != null)
{
n++;
}
EndPipeIn();
Console.WriteLine("Read " + n);
}
public static void Main(string[] args)
{
Thread first = new Thread(new ThreadStart(First));
first.Start();
Thread second = new Thread(new ThreadStart(Second));
second.Start();
first.Join();
second.Join();
Console.ReadLine();
}
}
}

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
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...
2
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...
2
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...
1
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...
4
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...
0
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...
2
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...
6
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...
0
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.