Code Monkey home page Code Monkey logo

Comments (4)

dwmkerr avatar dwmkerr commented on May 23, 2024

Hi @Loucool111 I would have to do a real deep dive here to understand why you don't get a change in value, but I expect it is down to the fact that you are essentially absolutely thrashing the main program thread because you are running a constant loop, with no breaks. In general, any kind of loop like this:

while(somethingThatIsTrueForALongTime)
{
  somethingThatIsQuickToDo();
}

Is going to quickly put the CPU to 100%, you don't give it any time to switch to other threads in the process. Running in the debugger means again you are probably artificially slowing things down enough. So even if you use this code, I would at least sleep for 1ms.

However, why not do something like this?

Stack<string> words = new Stack<String>(new[] { "one", "two", "three" });

        void ProcessWords()
        {
            //  Whenever a process is finished, if we still have words left to process, pop the stack
            //  and start processing the next word.
            processInterface.OnProcessExit += (sender, args) =>
            {
                if (words.Any())
                {
                    processInterface.StartProcess("someprogram", words.Pop());
                }
            };
           // Now just start
           StartProcess("something", words.Pop());
        }

You can get processInterface with view.console.ProcessInterface. Essentially what you are doing here is waiting for a process to exit. When it exists, if there are any words to process, start processing the next available.

from consolecontrol.

Werwolf696 avatar Werwolf696 commented on May 23, 2024

Yeah no this doesn't work at all... if I call processInterface.StartProcess() and then check "IsProcessRunning" it is false... so it seems you cannot tell when to issue the next processInterface.StartProcess(). You should have used a callback system where you could set a callback function to execute when the process finishes.

from consolecontrol.

AdamKlob avatar AdamKlob commented on May 23, 2024

I'm experiencing similar problem. What I also see, that the process starts, but does not seem to be running. I've created following workaraoud:

` public void StartProcess(string name, string args)
{
while(true)
{
try
{
consoleControl1.StartProcess(name, args);
}
catch (System.InvalidOperationException ex)
{
consoleControl1.StopProcess();
Application.DoEvents();
continue;
}

            break;
        }`

from consolecontrol.

AdamKlob avatar AdamKlob commented on May 23, 2024

It seems that the process when exits there is still (buffered?) lines to be sent to the richtextbox, and worker is busy with that.

from consolecontrol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.