110,535
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static string inputstr = ""; //退出指令
/// <summary
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
ThreadStart thr_start = new ThreadStart(first_Thread); //准备第一个线程
Console.WriteLine("Ready for start the first thread...");
Thread firstThread = new Thread(thr_start);
firstThread.Name = "first_thread";
ThreadStart thr_second = new ThreadStart(cmd_Thread); //准备第二个线程
Console.WriteLine("Ready for start the second thread...");
Thread cmdThread = new Thread(thr_second);
cmdThread.Name = "cmd_thread";
cmdThread.Start();
firstThread.Start();
}
/**
*主要是在命令行执行,将线程的主要工作及执行情况打印出来
*/
public static void cmd_Thread()
{
Console.WriteLine(System.DateTime.Now.ToString() + " Task running... Until input 'EXIT'");
while (!string.IsNullOrEmpty(inputstr) && inputstr.ToUpper() != "EXIT") //如果只有后面一段判断表达式则会抛NullReferenceException
{
inputstr = Console.ReadLine();
}
}
/**
*调用接口程序做到同步数据
*/
public static void first_Thread()
{
Console.WriteLine("开始执行。。。。");
while (inputstr == "" && inputstr.ToUpper() != "EXIT" && string.IsNullOrEmpty(inputstr))
{
//执行任务
}
Console.WriteLine("程序退出,谢谢使用。。。");
Thread.Sleep(2000);
}
}
if(!string.IsNullOrEmpty(str) && str.ToUpper() != "EX")