代码之家  ›  专栏  ›  技术社区  ›  Arlen Beiler

等待readline时,如何更新C_Windows控制台应用程序中的当前行?

  •  2
  • Arlen Beiler  · 技术社区  · 15 年前

    在C_中构建Windows控制台应用程序时,是否可以在等待读取行时更新控制台中的行?

    我当前的代码是:

    do
    {
        Console.Clear();
        Console.WriteLine("RA:     " + scope.RightAscension);
        Console.WriteLine("Dec:    " + scope.Declination);
        Console.WriteLine("Status: " + scope.Slewing);
        System.Threading.Thread.Sleep(1000);
    } while (true);
    
    3 回复  |  直到 15 年前
        1
  •  1
  •   Reed Copsey    15 年前


    namespace ConsoleApplication1
    {
        using System;
        using System.Threading;
    
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Starting");
    
                ThreadPool.QueueUserWorkItem(
                    cb =>
                        {
                            int i = 1;
                            while (true)
                            {
                                Console.WriteLine("Background {0}", i++);
                                Thread.Sleep(1000);
                            }
                        });
                Console.WriteLine("Blocking");
                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
            }
        }
    }
    

        2
  •  1
  •   Hans Passant    15 年前

        3
  •  0
  •   raisyn    15 年前

    using System; 
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    
    namespace WaitForExit
    {
        class Program
        {
            static void Main(string[] args)
            {
                new Thread(() =>
                    {
                        Console.ReadLine();
                        Environment.Exit(0);
                    }).Start();
    
                int i = 0;
                while (true)
                {
                    Console.Clear();
                    Console.WriteLine(++i);
                    Thread.Sleep(1000);
                }
            }
        }
    }    
    
    推荐文章