控制台程序
 运行后,留个10秒时间,等待输入参数, 若10秒内,没有输入,怎用默认参数,执行后续的代码 咋个写法? 谢谢

解决方案 »

  1.   


    static void Main(string[] args)
    {
        string input = "my default";
        Task.Factory.StartNew(() => { input = Console.ReadLine(); }).Wait(10 * 1000);
        Console.WriteLine(input);
    }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    using System.Windows.Forms;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "";
                bool inputted = false;
                System.Threading.Timer t = new System.Threading.Timer(new TimerCallback(o => { if (!inputted) SendKeys.SendWait("{enter}"); }), null, 10 * 1000, 0);
                s = Console.ReadLine();
                inputted = true;
                Console.WriteLine(s);
            }
        }
    }添加引用 System.Windows.Forms