学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

问题,关于线程的

问题,关于线程的

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?

TOP

public sealed delegate TimerCallback //时间回调函数

System.MulticastDelegate 和 System.Threading 的成员

表示处理来自 System.Threading.Timer 的调用的方法。

TOP

E:\C++\ConsoleApplication1\Class1.cs(18): 方法“Temp4.Class1.GetText()”与委托“void System.Threading.TimerCallback(object)”不匹配

该函数是委托,它的原身有参数。

关于整个代码我未看懂,因为有些函数还没看。不好意思,马上下去恶补。

TOP

发新话题