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 { }
    }
}

  

posted @ 2016-10-10 11:22  microsoftzhcn  阅读(706)  评论(0编辑  收藏  举报