using System; using System.Threading;namespace ConsoleApplication1 { /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { /// <summary> /// 应用程序的主入口点。 /// </summary> //private static
[STAThread] static void Main(string[] args) { State s = new State(); Timer timer1 = new Timer(new TimerCallback(Queue_RecvMessageThread),s,0,1000); s.timer = timer1;
string cmd = "";
do { cmd = Console.ReadLine().ToLower(); switch(cmd) { case "stop": s.command = "STOP"; break;
default: Console.Write("? For Help>>"); break; } }while(cmd != "exit"); }
static void Queue_RecvMessageThread(object o) { State s = o as State; switch(s.command) { case "STOP": Console.WriteLine("STOP!!!"); s.timer.Change(Timeout.Infinite,0); return; default: break; }
Console.WriteLine("working .. ..."); } } class State { internal string command; internal Timer timer; } }
using System.Threading;namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
//private static
[STAThread]
static void Main(string[] args)
{
State s = new State();
Timer timer1 = new Timer(new TimerCallback(Queue_RecvMessageThread),s,0,1000);
s.timer = timer1;
string cmd = "";
do
{
cmd = Console.ReadLine().ToLower();
switch(cmd)
{
case "stop":
s.command = "STOP";
break;
default:
Console.Write("? For Help>>");
break;
}
}while(cmd != "exit");
}
static void Queue_RecvMessageThread(object o)
{
State s = o as State;
switch(s.command)
{
case "STOP":
Console.WriteLine("STOP!!!");
s.timer.Change(Timeout.Infinite,0);
return; default:
break;
}
Console.WriteLine("working .. ...");
}
}
class State
{
internal string command;
internal Timer timer;
}
}