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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript