EDN Admin
Well-known member
Hi,
I have written a GUI front end to a console application, used for programming a microcontoller, using ProcessStartInfo. If I run either the debug, or release build from within the Visual studio 2008 environment, the application runs correctly. If I run the
release build by running the .exe file I only see the first line of the console output, if I run the debug build it works fine.
Can some please explain what is going wrong here. I have pasted the code below.
Thanks
Andrew
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace BollardProgrammer
{
public partial class BollardProgrammer : Form
{
private static String sVerbose;
String sFileName;
bool bInvalid = false;
static int idx = 0;
List<string> verboseList = new List<string>();
public BollardProgrammer()
{
InitializeComponent();
string path = Environment.CurrentDirectory;
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo f in dir.GetFiles("*.elf"))
{
string name = f.Name;
lbFiles.Items.Add(name);
}
}
private void programVerboseHandler(object sendingProcess,
DataReceivedEventArgs e)
{
sVerbose = e.Data;
verboseList.Add(sVerbose);
pnlVerbose.Invalidate();
bInvalid = true;
while (bInvalid) ;
}
private void pnlVerbose_Paint(object sender, PaintEventArgs e)
{
int i;
Control c = sender as Control;
using (Font f = new Font("Ariel", 8))
{
for(i = 0; i < verboseList.Count; i++)
{
try
{
e.Graphics.DrawString(verboseList.ToString(), f, Brushes.Green, new PointF(1, 1 + idx));
bInvalid = false;
idx += 12;
}
catch (Exception ex)
{
}
}
idx = 0;
}
}
private void btnProgram_Click(object sender, EventArgs e)
{
String sArgs;
int i = 0;
i = lbFiles.SelectedIndex;
idx = 0;
verboseList.Clear();
if (i >= 0)
{
sFileName = lbFiles.Items.ToString();
sArgs = String.Format("-device at32uc3b0512 -hardware usb -operation erase f memory flash loadbuffer {0} program verify onfail abort memory configuration addrange 0x1D 0x1D fillbuffer 0x0 program addrange 0x1E 0x1E fillbuffer 0x0 program addrange 0x1F 0x1F fillbuffer 0x0 program start reset 0", sFileName);
var processStartInfo = new ProcessStartInfo("batchisp", sArgs);
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = processStartInfo;
// Set UseShellExecute to false for redirection.
process.StartInfo.UseShellExecute = false;
// Set our event handler to asynchronously read the sort output.
process.OutputDataReceived += new DataReceivedEventHandler(programVerboseHandler);
// Redirect standard input as well. This stream
// is used synchronously.
// process.StartInfo.RedirectStandardInput = true;
bool processStarted = process.Start();
// Start the asynchronous read of the sort output stream.
process.BeginOutputReadLine();
StreamWriter inputWriter = process.StandardInput;
}
}
}
}
[/code]
<br/>
View the full article
I have written a GUI front end to a console application, used for programming a microcontoller, using ProcessStartInfo. If I run either the debug, or release build from within the Visual studio 2008 environment, the application runs correctly. If I run the
release build by running the .exe file I only see the first line of the console output, if I run the debug build it works fine.
Can some please explain what is going wrong here. I have pasted the code below.
Thanks
Andrew
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace BollardProgrammer
{
public partial class BollardProgrammer : Form
{
private static String sVerbose;
String sFileName;
bool bInvalid = false;
static int idx = 0;
List<string> verboseList = new List<string>();
public BollardProgrammer()
{
InitializeComponent();
string path = Environment.CurrentDirectory;
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo f in dir.GetFiles("*.elf"))
{
string name = f.Name;
lbFiles.Items.Add(name);
}
}
private void programVerboseHandler(object sendingProcess,
DataReceivedEventArgs e)
{
sVerbose = e.Data;
verboseList.Add(sVerbose);
pnlVerbose.Invalidate();
bInvalid = true;
while (bInvalid) ;
}
private void pnlVerbose_Paint(object sender, PaintEventArgs e)
{
int i;
Control c = sender as Control;
using (Font f = new Font("Ariel", 8))
{
for(i = 0; i < verboseList.Count; i++)
{
try
{
e.Graphics.DrawString(verboseList.ToString(), f, Brushes.Green, new PointF(1, 1 + idx));
bInvalid = false;
idx += 12;
}
catch (Exception ex)
{
}
}
idx = 0;
}
}
private void btnProgram_Click(object sender, EventArgs e)
{
String sArgs;
int i = 0;
i = lbFiles.SelectedIndex;
idx = 0;
verboseList.Clear();
if (i >= 0)
{
sFileName = lbFiles.Items.ToString();
sArgs = String.Format("-device at32uc3b0512 -hardware usb -operation erase f memory flash loadbuffer {0} program verify onfail abort memory configuration addrange 0x1D 0x1D fillbuffer 0x0 program addrange 0x1E 0x1E fillbuffer 0x0 program addrange 0x1F 0x1F fillbuffer 0x0 program start reset 0", sFileName);
var processStartInfo = new ProcessStartInfo("batchisp", sArgs);
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = processStartInfo;
// Set UseShellExecute to false for redirection.
process.StartInfo.UseShellExecute = false;
// Set our event handler to asynchronously read the sort output.
process.OutputDataReceived += new DataReceivedEventHandler(programVerboseHandler);
// Redirect standard input as well. This stream
// is used synchronously.
// process.StartInfo.RedirectStandardInput = true;
bool processStarted = process.Start();
// Start the asynchronous read of the sort output stream.
process.BeginOutputReadLine();
StreamWriter inputWriter = process.StandardInput;
}
}
}
}
[/code]
<br/>
View the full article