WPF 定時寫入文本

public static void Start()
{
    ThreadStart start = new ThreadStart(ThreadAction);
    Thread th = new Thread(start);
    th.IsBackground = true;
    th.Start();
}
public static void ThreadAction()
{
    while (true)
    {
        try
        {
            System.Threading.Thread.Sleep(3000);
            StreamWriter fs = System.IO.File.AppendText("c:\\microservice\\log.txt");
            //開始寫入
            fs.WriteLine(string.Format("WinS {0}", DateTime.Now));
            fs.Close();
        }
        catch { }
    }
}
相關文章
相關標籤/搜索