3
static Timer _timer;
static void Main(string[] args)
{
_timer = new Timer(1000);
_timer.Enabled = true;
_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
for (int i = 0; i < 10000; i++)
{
string strXMLComperator = @"D:\randomFiles\rand" + i + ".txt";
if (!File.Exists(strXMLComperator))
{
StreamWriter sWriter = new StreamWriter(strXMLComperator, false, Encoding.UTF8);
sWriter.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?><catalog>dasd</catalog>");
sWriter.Flush();
sWriter.Close();
sWriter.Dispose();
}
}
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//some code here
}
我想知道會main()方法添加文件時OnTimedEvent工程或將停止工作,同時timer_event完成定時器在C#中使用不同的線程
System.Timers.Timer – AEMLoviji 2010-09-27 06:07:30
真的嗎? OnTimedEvent()和Main()在不同的線程中工作?這意味着所有將正常工作主要方法將添加文件和相同的時間計時器會做一些思考。我usin System.Timers.Timer – AEMLoviji 2010-09-27 06:09:29
@AemLoviji:是的......根據文檔:「Elapsed事件引發一個ThreadPool線程」 – 2010-09-27 06:17:08