|
So you're saying that attempt failed. There are maybe a dozen more ways to do things. I suggest you dedicate a thread (could be a BGW); that way you don't need a timer, don't need Peek at all, you just do a blocking ReadLine in a loop, until the main thread decides all is done. I did this, all the way back, using .NET 1.0 and Windows 98, and I can assure you there have been some bugs in .NET 1.x making it pretty hard; Since NT/XP the code got simpler and it now runs like a charm, one thread for stdout, one for stderr, and their output intertwines as it would in a DOS window (Command Prompt).
Here is a typical receiver thread (the output() method is likely to contain a Control.Invoke):
private void stdoutReader(object dummy) {
for (; threadsRunning && stdoutLines<maxLines; stdoutLines++) {
string s=stdout.ReadLine();
if (s==null) break;
output(s);
}
stdoutDone=true;
}
Mind you, there is some buffering going on, in the target app and in your app, so don't expect the output right away, there will be say some delays, but not seconds, and certainly not till the target app finishes. And the DOS prompt/command window (or something deep inside Windows) is smart enough to adapt the buffering depending on how things get used, so a pipe may well have a larger buffer than a direct interactive invocation.
Due to the buffering and sometimes automatic but delayed flushing, determining the end of the output may be a little tricky too; here is one possibility (code executed in the main thread):
proc.WaitForExit();
for (; ; ) {
if (stdoutDone&&stderrDone) break;
int cur=stdoutLines+stderrLines;
Thread.Sleep(500);
if (cur>=stdoutLines+stderrLines) break;
}
threadsRunning=false;
|
|
|
|
|
Thanks for your tips. Still no luck. Code based on your clear tips below. I must admit that I didn't expect this to work since it is essentially the same as my previous attempt.
In my previou spost I mentioned that while running the console program from a command window displayed output neatly; every now and then a line of text. When adding " > output.log" to the command line, all output winds up in output.log but NOT UNTILL the console program finishes! So here we have the same behaviour as in my c# program! Perhaps the cause is the fact that this is not a native windows console program; it need cygwin1.dll to work. Might this cause the strange behaviour?
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Process process;
private void Form1_Load(object sender, EventArgs e)
{
process = new Process();
process.StartInfo.FileName = @"D:\Users\Jan C. de Graaf\Documents\Othello\test\zebra.exe";
process.StartInfo.Arguments = "-b 0 -h 24 -l 28 30 30 28 30 30 -r 0 -slack 0.0 -learn 26 22 -private -log hqbook.txt -test";
process.StartInfo.WorkingDirectory = @"D:\Users\Jan C. de Graaf\Documents\Othello\test";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
var thread = new Thread(new ThreadStart(GetOutputAndDisplay));
thread.Start();
textBox1.Text = "Started!\r\n";
}
void GetOutputAndDisplay()
{
string output;
do
{
output = process.StandardOutput.ReadLine();
textBox1.Invoke((MethodInvoker)delegate { textBox1.Text += output + "\r\n"; });
}
while (output != null);
}
}
}
|
|
|
|
|
jancg wrote: t need cygwin1.dll to work. Might this cause the strange behaviour?
Absolutely. It tells me your target app is essentially a kind of Unix/Linux thingy, and CYGWIN has to do god knows what to make it behave (a bit) under Windows.
There still might be a solution, however I don't know it; I'm unfamiliar with the CYGWIN + .NET combination.
If the app is related to www.zebra.com by chance, you might ask them; they just might have run into this before and hold a solution.
|
|
|
|
|
|
|
Please don't crosspost. You already asked the same question in the Q&A section.
|
|
|
|
|
Hi Dears,
I wish to design Typing Tutor software, I need your help, Kindly let me know that,
How may I start and what are related methods and example, if you have or know.\
Thank you
(Riaz)
|
|
|
|
|
Whilst this isn't a terribly complex bit of software to write it is sufficiently complicated for us not to be able to provide you with an answer. What you want this to do, you need to figure out for youself, we can't and won't do this for you. This forum is for programming questions, you are askng for analysis.
To Start I'd say, you need to figure out a basic process to teach typing (videos needed? user metrics(WPM/Accuracy) at the very least a control that allows the learner to type text and checks for errors, speed etc, ), then start to implement that. You also need to figure out how much time and effort you can/want to put into this, and change the quantity/comprehensiveness of features accordingly.
Finally, as a peice of advice, don't start a question with "Hello Dears", to most of the English-speaking world it is similar to saying "Hello my darlings". I realise it's common to address people this way in India & Pakistan ( and the Middle East, but in Arabic/Farsi) but outside these area it sounds effete. Ask around in the General Indian Topics[^] forum for the cross-cultural woes they've had.
|
|
|
|
|
hello how do i get the color value in an array and append it to a panel showing its actual color as well as display r, g and b color value in a textbox?
|
|
|
|
|
Hi,
here is the code you wanted. An array of colors and how you can get one single color as background and how you get the value of the single color layer as string.
System.Drawing.Color[] arrColor = new System.Drawing.Color[20];
arrColor[0] = System.Drawing.Color.FromArgb(5, 5, 5);
textBox1.Text = arrColor[0].R.ToString();
panel1.BackColor = arrColor[0];
|
|
|
|
|
What is the value stored in my array as this value? [Color[A=255, R=255, G=0, B=0]
|
|
|
|
|
I have no idea what you mean with this question - please show us a bit of your code.
|
|
|
|
|
string[] mainColor = listBox10.Items.OfType<object>().Select(item => item.ToString()).ToArray();
I declared this particular array where by it stored many values example( Color[A=255, R= 255, G= 0, B= 0] ) in the listbox.
how to assign the first array to a panel showing the actual color? and RGB number values to textboxes?
modified on Wednesday, November 24, 2010 4:18 AM
|
|
|
|
|
Seeing the questions you have posted here in the last days, I think you have the bad habit of using ToString() method for everything, no matter if it is indeed a string, or a number, or a color, or whatever. If you want an array of colors, why do you declare a string[] array? Which is the type of the items you have in your ListBox ? The string you are showing us ( Color[A=255, R= 255, G= 0, B= 0] ) is exactly what an object of Color type returns when you invoke its ToString() method so, how did you add the colors to the ListBox? Did you add the Color objects or did you also invoke ToString method to add them? I mean, if "c" object is a Color object, did you do this:
ListBox.Items.Add(c);
Or did yo do this:
ListBox.Items.Add(c.ToString());
I am asking becouse in both cases you would see the same result in the ListBox. However, in the first case the items are Color objects, so you only have to cast them to Color type:
Color[] colors = listBox10.Items.Cast<Color>().ToArray();
But in the second case the problem is harder becouse you should parse each string. Summarizing, as a piece of advise, use ToString method only when you need a string object.
|
|
|
|
|
when i use
listBox10.Items.Add(d);
the listbox do not display their color values but just "(Collection)"
my code as shown below"
Dictionary<Color, int> d = new Dictionary<Color, int>();
Color c;
Bitmap checkColor = new Bitmap(pictureBox2.Image);
for (int i = 0; i < checkColor.Width; i++)
{
for (int j = 0; j < checkColor.Height; j++)
{
c = checkColor.GetPixel(i, j);
if (d.ContainsKey(c))
d[c]++;
else
d.Add(c, 1);
}
listBox10.Items.Add(d);
}
I wanted to find the main colors of an image. so i use count colors however unsure of how it shld go abt doing it. any idea?
modified on Wednesday, November 24, 2010 10:31 PM
|
|
|
|
|
You see "(Collection)" in the listBox becouse there is a little mistake in your program. See this:
Dictionary<Color, int> d = new Dictionary<Color, int>();
listBox10.Items.Add(d);
You are adding the Dictionary object to the listBox, not the Color objects. Remove that line and put this one at the end:
listBox10.Items.AddRange(d.Keys);
However, I don't know how adding the colors to a ListBox could help you. What you want to do is color quantization and, belive me, it is not a trivial task. You need to write an algorithm for clustering the colors. You might consider every color as a point in a three dimensional space, so any three dimensional clustering algorithm would help you for what you need. Once you have the colors clustered, you should only average each cluster and make the replace.
modified on Thursday, November 25, 2010 11:12 AM
|
|
|
|
|
What is the best class(es) to use to get the properties of the system your app is running on.
For example:
Total RAM
Video Card
Detailed CPU info
etc.
I have tried some articles but the classes they suggest are either obsolete or incomplete.
Thanks.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
|
Thanks. I did use this. It has some info but is limited on the hardware details.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
I use a mix of System.Environment, WMI classes (System.Management), Win32 functions (through P/Invoke), some registry accesses, and some assembly code, and still I'm not getting all I would like to collect.
FWIW: MS guidelines will tell you your app shouldn't be interested nor care. However I understand knowing the characteristics of a platform and logging them can be very relevant in debugging an app with multiple and various customers.
|
|
|
|
|
Thanks. Can you provide a little more detail please. Class names, ...
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
I'm not going to copy dozens of class names, methods, dlls, function names.
If you have a very specific requirement, I'll see what I can provide.
And it wouldn't hurt if you explained a bit why you need those things, the best way may depend on it, as accuracy, performance and prerequisites may vary.
|
|
|
|
|
Sorry. I did not realize that would be necessary. Thanks for the guidance. I'll try to take it from here.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
Luc Pattyn wrote: knowing the characteristics of a platform and logging them can be very relevant in debugging an app with multiple and various customers
That's terribly true!
|
|
|
|
|
Precisely. That is one reason I would like to have the techniques in place. I do use an exception capture form and logging system that encourages user input and email responses from the form.
Having a good relevant H/W and S/W profile is very useful. Many users cannot answer/or will not answer questions about there configurations.
I am making some progress on getting more details. I am not happy with it yet. Any ideas on Classes to use and Code snippets are welcome.
Thanks.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|