• Asp.net 定时写入文本记录


    Asp.net 定时写入文本记录

    		public static string FileAddress = "c:\TimerLog.txt";
            protected void Page_Load(object sender, EventArgs e)
            {
                // 在应用程序启动时运行的代码
                var myTimer = new System.Timers.Timer(60000);
                myTimer.Elapsed += OnTimedEvent;
                myTimer.Interval = 60000;
                myTimer.Enabled = true;
            }
    
            private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
            {
                WriteString(DateTime.Now.ToString());
            }
     
            public static void WriteString(string pPhone)
            {
                FileStream fs = null;
                if (!File.Exists(FileAddress))
                {
                    fs = new FileStream(FileAddress, FileMode.Create);
                }
                else
                {
                    fs = new FileStream(FileAddress, FileMode.Append);
                }
    
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine("—————————————————————————————–");
                sw.WriteLine("日    期:" + DateTime.Now.ToString("G"));
                sw.WriteLine("手机|内容|结果:" + pPhone);
                sw.WriteLine("—————————————————————————————–");
                sw.Close();
            }
  • 相关阅读:
    RabbitMQ简介、特性、使用场景、安装、启动与关闭
    mybatis的工作原理
    bzoj2119 股市的预测
    Noi2014 购票
    51Nod 算法马拉松22 开黑记
    COGS2485 从零开始的序列
    Codeforces Round #402 (Div.2)
    BestCoder Round #92
    COGS2294 释迦
    bzoj4764 弹飞大爷
  • 原文地址:https://www.cnblogs.com/renzaijianghu/p/4269348.html
Copyright © 2020-2023  润新知