c# GUI freezes after launching console application Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Why is my process's Exited method not being called?How can I get the application's path in a .NET console application?how to change a button into a imagebutton in asp.net c#Dataset.GetChanges(DataRowState.Modified) return nullWhy is my C# application code not working with my GUI?C# How use sign from another window?C# method failing to function for no known reasonHow to show Rss on my pageFilename pattern not working in OpenFileDialogHow to programatically submit form of certain ID on 3rd person's websiteC# Directx App crashes in Release

Can a party unilaterally change candidates in preparation for a General election?

How to tell that you are a giant?

What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in ITSV

Is safe to use va_start macro with this as parameter?

What does "lightly crushed" mean for cardamon pods?

How do pianists reach extremely loud dynamics?

old style "caution" boxes

What do you call the main part of a joke?

What is the longest distance a player character can jump in one leap?

Why are there no cargo aircraft with "flying wing" design?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How could we fake a moon landing now?

How to answer "Have you ever been terminated?"

Around usage results

Amount of permutations on an NxNxN Rubik's Cube

Is this homebrew Lady of Pain warlock patron balanced?

Do square wave exist?

For a new assistant professor in CS, how to build/manage a publication pipeline

Should I use a zero-interest credit card for a large one-time purchase?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Closed form of recurrent arithmetic series summation

Does classifying an integer as a discrete log require it be part of a multiplicative group?

How would a mousetrap for use in space work?

Is the Standard Deduction better than Itemized when both are the same amount?



c# GUI freezes after launching console application



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Why is my process's Exited method not being called?How can I get the application's path in a .NET console application?how to change a button into a imagebutton in asp.net c#Dataset.GetChanges(DataRowState.Modified) return nullWhy is my C# application code not working with my GUI?C# How use sign from another window?C# method failing to function for no known reasonHow to show Rss on my pageFilename pattern not working in OpenFileDialogHow to programatically submit form of certain ID on 3rd person's websiteC# Directx App crashes in Release



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















I make an application that runs ping and displays the result in a text field. When I click the start ping button, the GUI hangs and nothing is output to the text field. Why this GUI hangs is understandable, the GUI is waiting for the console application to finish. I do not understand how then to implement the output in the text field from the console application.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApp4

public partial class Form1 : Form

public Form1()

InitializeComponent();


private void button1_Click(object sender, EventArgs e)

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();


static private void richTextBox1_TextChanged(object sender, EventArgs e)





class Class1

private Process p = new Process();

public void startPing()

p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "c:/windows/system32/ping";
p.StartInfo.Arguments = "8.8.8.8 -t";
p.Start();


public string output()

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;












share|improve this question






















  • The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

    – MindSwipe
    Mar 22 at 9:28






  • 3





    What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

    – mjwills
    Mar 22 at 9:28












  • There are also a lot of examples on pulling the results from the console into c#

    – BugFinder
    Mar 22 at 9:28











  • Possible duplicate of Why is my process's Exited method not being called?

    – mjwills
    Mar 22 at 9:29











  • Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

    – Dmitry Bychenko
    Mar 22 at 9:45


















-3















I make an application that runs ping and displays the result in a text field. When I click the start ping button, the GUI hangs and nothing is output to the text field. Why this GUI hangs is understandable, the GUI is waiting for the console application to finish. I do not understand how then to implement the output in the text field from the console application.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApp4

public partial class Form1 : Form

public Form1()

InitializeComponent();


private void button1_Click(object sender, EventArgs e)

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();


static private void richTextBox1_TextChanged(object sender, EventArgs e)





class Class1

private Process p = new Process();

public void startPing()

p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "c:/windows/system32/ping";
p.StartInfo.Arguments = "8.8.8.8 -t";
p.Start();


public string output()

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;












share|improve this question






















  • The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

    – MindSwipe
    Mar 22 at 9:28






  • 3





    What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

    – mjwills
    Mar 22 at 9:28












  • There are also a lot of examples on pulling the results from the console into c#

    – BugFinder
    Mar 22 at 9:28











  • Possible duplicate of Why is my process's Exited method not being called?

    – mjwills
    Mar 22 at 9:29











  • Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

    – Dmitry Bychenko
    Mar 22 at 9:45














-3












-3








-3








I make an application that runs ping and displays the result in a text field. When I click the start ping button, the GUI hangs and nothing is output to the text field. Why this GUI hangs is understandable, the GUI is waiting for the console application to finish. I do not understand how then to implement the output in the text field from the console application.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApp4

public partial class Form1 : Form

public Form1()

InitializeComponent();


private void button1_Click(object sender, EventArgs e)

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();


static private void richTextBox1_TextChanged(object sender, EventArgs e)





class Class1

private Process p = new Process();

public void startPing()

p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "c:/windows/system32/ping";
p.StartInfo.Arguments = "8.8.8.8 -t";
p.Start();


public string output()

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;












share|improve this question














I make an application that runs ping and displays the result in a text field. When I click the start ping button, the GUI hangs and nothing is output to the text field. Why this GUI hangs is understandable, the GUI is waiting for the console application to finish. I do not understand how then to implement the output in the text field from the console application.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApp4

public partial class Form1 : Form

public Form1()

InitializeComponent();


private void button1_Click(object sender, EventArgs e)

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();


static private void richTextBox1_TextChanged(object sender, EventArgs e)





class Class1

private Process p = new Process();

public void startPing()

p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "c:/windows/system32/ping";
p.StartInfo.Arguments = "8.8.8.8 -t";
p.Start();


public string output()

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;









c#






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 9:26









MichaelMichael

12




12












  • The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

    – MindSwipe
    Mar 22 at 9:28






  • 3





    What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

    – mjwills
    Mar 22 at 9:28












  • There are also a lot of examples on pulling the results from the console into c#

    – BugFinder
    Mar 22 at 9:28











  • Possible duplicate of Why is my process's Exited method not being called?

    – mjwills
    Mar 22 at 9:29











  • Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

    – Dmitry Bychenko
    Mar 22 at 9:45


















  • The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

    – MindSwipe
    Mar 22 at 9:28






  • 3





    What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

    – mjwills
    Mar 22 at 9:28












  • There are also a lot of examples on pulling the results from the console into c#

    – BugFinder
    Mar 22 at 9:28











  • Possible duplicate of Why is my process's Exited method not being called?

    – mjwills
    Mar 22 at 9:29











  • Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

    – Dmitry Bychenko
    Mar 22 at 9:45

















The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

– MindSwipe
Mar 22 at 9:28





The GUI freezes because you're running your ping on the same thread as the GUI, thus blocking it from updating until your operation has finished, you might want to look into starting up a new thread or background worker and running the ping on it

– MindSwipe
Mar 22 at 9:28




3




3





What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

– mjwills
Mar 22 at 9:28






What do you think p.WaitForExit(); does? Does the documentation suggest an alternate approach? docs.microsoft.com/en-us/dotnet/api/…

– mjwills
Mar 22 at 9:28














There are also a lot of examples on pulling the results from the console into c#

– BugFinder
Mar 22 at 9:28





There are also a lot of examples on pulling the results from the console into c#

– BugFinder
Mar 22 at 9:28













Possible duplicate of Why is my process's Exited method not being called?

– mjwills
Mar 22 at 9:29





Possible duplicate of Why is my process's Exited method not being called?

– mjwills
Mar 22 at 9:29













Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

– Dmitry Bychenko
Mar 22 at 9:45






Try using p.Exited event (do not forget to allow it - p.EnableRaisingEvents = true;) and drop p.WaitForExit();

– Dmitry Bychenko
Mar 22 at 9:45













1 Answer
1






active

oldest

votes


















-3














This code will usefull to resolve your query.



 private void button1_Click(object sender, EventArgs e)

var worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();

;
worker.RunWorkerCompleted += (o, ea) =>

//You will get pointer when this worker finished the job.
;
worker.RunWorkerAsync();



Let me know if any issue after implement it with your source.






share|improve this answer























  • Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

    – T_Bacon
    Mar 22 at 9:38











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296494%2fc-sharp-gui-freezes-after-launching-console-application%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-3














This code will usefull to resolve your query.



 private void button1_Click(object sender, EventArgs e)

var worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();

;
worker.RunWorkerCompleted += (o, ea) =>

//You will get pointer when this worker finished the job.
;
worker.RunWorkerAsync();



Let me know if any issue after implement it with your source.






share|improve this answer























  • Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

    – T_Bacon
    Mar 22 at 9:38















-3














This code will usefull to resolve your query.



 private void button1_Click(object sender, EventArgs e)

var worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();

;
worker.RunWorkerCompleted += (o, ea) =>

//You will get pointer when this worker finished the job.
;
worker.RunWorkerAsync();



Let me know if any issue after implement it with your source.






share|improve this answer























  • Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

    – T_Bacon
    Mar 22 at 9:38













-3












-3








-3







This code will usefull to resolve your query.



 private void button1_Click(object sender, EventArgs e)

var worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();

;
worker.RunWorkerCompleted += (o, ea) =>

//You will get pointer when this worker finished the job.
;
worker.RunWorkerAsync();



Let me know if any issue after implement it with your source.






share|improve this answer













This code will usefull to resolve your query.



 private void button1_Click(object sender, EventArgs e)

var worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>

Class1 ping = new Class1();
ping.startPing();
string output = ping.output();
richTextBox1.AppendText(output + "n");
richTextBox1.Update();

;
worker.RunWorkerCompleted += (o, ea) =>

//You will get pointer when this worker finished the job.
;
worker.RunWorkerAsync();



Let me know if any issue after implement it with your source.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 9:34









ShSakariyaShSakariya

162




162












  • Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

    – T_Bacon
    Mar 22 at 9:38

















  • Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

    – T_Bacon
    Mar 22 at 9:38
















Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

– T_Bacon
Mar 22 at 9:38





Just posting code doesn't help the OP understand the solution. Please provide an explanation along with the code.

– T_Bacon
Mar 22 at 9:38



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296494%2fc-sharp-gui-freezes-after-launching-console-application%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?