简体   繁体   English

如何在文本文件中保存应用程序的启动和关闭时间?

[英]How to save application start-up and close time in text file?

Just this - whlie running its showing error: Object reference not set to an instance of an object 就是这样-运行其显示错误: 对象引用未设置为对象的实例

please help 请帮忙

what is it means? 什么意思 instead of that which code should I use? 而不是我应该使用哪个代码?

using System;
using System.Windows.Forms;
using System.Text;
using System.IO;

namespace Charts
{
System.Timers.Timer myTimer = new System.Timers.Timer();
public partial class Form1 : Form
{
    private StringBuilder sb;
    public Form1()
    {
        InitializeComponent();
    }

private void Form1_Load(object sender, EventArgs e)
    {
      try {  
        this.chart1.Series["Performance"].Points.AddXY("me", 44);
        this.chart1.Series["Performance"].Points.AddXY("Year", 66);
        this.chart1.Text.Clone();
        timer1.Start();

        File.WriteAllText(String.Format(@"D:\Log at {0:yyyy-MM-dd HH:mm:ss}.txt", DateTime.Now), sb.ToString());
     }   
    catch (Exception ex)
        { MessageBox.Show(ex.Message); }
    }
}
}

You have an object not initialized. 您有一个未初始化的对象。 Probably your StringBuilder sb or your timer. 可能是您的StringBuilder sb或您的计时器。

You should have a line with something like 你应该写一条类似

sb = new StringBuilder();

在调用timer1.start()之前,必须在某个地方初始化timer1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM