Skip to content

Commit 7cd7d59

Browse files
committed
using OutputDataReceived
1 parent 92a0dd8 commit 7cd7d59

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

easyDe4dot/Form1.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ private void StartDe4dot(){
140140
sinfo.FileName = chk64.Checked ? de4dot64 : de4dot;
141141
sinfo.RedirectStandardOutput = true;
142142
sinfo.UseShellExecute = false;
143-
sinfo.CreateNoWindow = true;
143+
sinfo.CreateNoWindow = true;
144+
process.OutputDataReceived += new DataReceivedEventHandler(DataReceived);
144145
process.StartInfo = sinfo;
146+
145147

146148
txtLog.Text = "Command line : " + sinfo.Arguments + Environment.NewLine;
147149
txtLog.AppendText("Starting de4dot" + Environment.NewLine);
@@ -150,21 +152,19 @@ private void StartDe4dot(){
150152
{
151153
txtLog.AppendText("Process started" + Environment.NewLine);
152154
txtLog.AppendText("----------------" + Environment.NewLine);
153-
154-
while (!process.HasExited)
155-
{
156-
string line = process.StandardOutput.ReadLine();
157-
if (line!=null && line != "")
158-
txtLog.AppendText(line +Environment.NewLine);
159-
}
155+
process.BeginOutputReadLine();
156+
process.WaitForExit();
160157
txtLog.AppendText("----------------" + Environment.NewLine);
161-
txtLog.AppendText("Process terminated");
162-
158+
txtLog.AppendText("Process exited" + Environment.NewLine);
163159
}
164160
else
165161
txtLog.AppendText("!Failed to start process" + Environment.NewLine);
166162
}
167163

164+
private void DataReceived(object Sender,DataReceivedEventArgs e)
165+
{
166+
txtLog.AppendText(e.Data + Environment.NewLine);
167+
}
168168
private void btnClear_Click(object sender, EventArgs e)
169169
{
170170
txtLog.Text = "";

0 commit comments

Comments
 (0)