title: C# console application design like htop
body: <p>I want to build console application with similar interface like htop's one (fixed console design). Here is a link to htop console design: <a href="http://upload.wikimedia.org/wikipedia/commons/b/b1/Htop.png" rel="nofollow">http://upload.wikimedia.org/wikipedia/commons/b/b1/Htop.png</a>. I wanted to ask how can I build application like this as I only know C#'s <code>Console.Write()</code> method. I am writing simple program that is starting up applications via <code>Process.Start()</code> and then I am monitoring for example their RAM usage via <code>Process.WorkingSet64</code> and outputing it via simple <code>Console.WriteLine()</code> each line to console. But how could I design C# console application like htop so it has fixed design that will be for example refreshing every 1 second. By fixed designed I mean that I it will be fixed position on the console where I will print out process names, ram usage, application name, etc. Here is my code of the program:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          string[] myApps = { "notepad.exe", "calc.exe", "explorer.exe" };
  
          Thread w;
          ParameterizedThreadStart ts = new ParameterizedThreadStart(StartMyApp);
          foreach (var myApp in myApps)
          {
              w = new Thread(ts);
              w.Start(myApp);
              Thread.Sleep(1000);
          }
      }
  
      public static void StartMyApp(object myAppPath)
      {
          ProcessStartInfo myInfoProcess = new ProcessStartInfo();
          myInfoProcess.FileName = myAppPath.ToString();
          myInfoProcess.WindowStyle = ProcessWindowStyle.Minimized;
          Process myProcess = Process.Start(myInfoProcess);
  
          do
          {
              if (!myProcess.HasExited)
              {
                  myProcess.Refresh(); // Refresh the current process property values.
                  Console.WriteLine(myProcess.ProcessName+" RAM: " + (myProcess.WorkingSet64 / 1024 / 1024).ToString() + "\n");
                  Thread.Sleep(1000);
              }
          }
          while (!myProcess.WaitForExit(1000)); 
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>: Thanks for pointing to <code>Console.SetCursorPosition</code> @Jim Mischel. I want to use that in my application but now I have another problem. How could I pass to my <code>StartMyApp</code> method, the index number from <code>myApps</code> array so I could do something like:</p>
  
  <pre><code>Console.WriteLine((Array.IndexOf(myApps, myAppPath) + " " + myProcess.ProcessName+" RAM: "+ (myProcess.WorkingSet64 / 1024 / 1024).ToString() + "\n");
  </code></pre>
  
  <p>That is inside my <code>StartMyApp</code> method. Any method I use I end up getting <code>The name 'myApps' does not exist in the current context</code>. This is very important for me so I could design my application later using <code>Console.SetCursorPosition</code> but I need that index number. So my output would be for example:</p>
  
  <pre><code>0 notepad RAM: 4
  1 calc RAM: 4
  2 explorer RAM: 12
  </code></pre>