using System; using System.Threading; using System.Text;
namespace Temp4 { class Class1 { private string message; private static Timer tmr; private static bool complete; [STAThread] static void Main(string[] args) { Class1 obj=new Class1(); Thread t=new Thread(new ThreadStart(obj.GenerateText)); t.Start(); TimerCallback trmCallBack=new TimerCallback(obj.GetText); tmr=new Timer(trmCallBack,null,TimeSpan.Zero,TimeSpan.FromSeconds(2)); do { if (complete) break; }while (true); Console.WriteLine("Exiting Main..."); } public void GetText(object state) { if (message==null) return; Console.WriteLine("Message is:"); Console.WriteLine(message); tmr.Dispose(); complete=true;
} public void GenerateText() { StringBuilder sb=new StringBuilder(); for (int i=1;i<200;i++) { sb.Append("This is Line"); sb.Append(i.ToString()); sb.Append(System.Environment.NewLine); } message=sb.ToString(); }
} } 红颜色的两行怎么解释?为什么public void GetText(object state)有object state?