110,539
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 日志消息
/// </summary>
/// <param name="str">消息字符串</param>
private delegate void SetTextGridCallBack(string str);
private void SetText(string str)
{
try
{
if (this.listBox1.InvokeRequired)
{
SetTextGridCallBack cb = new SetTextGridCallBack(SetText);
this.listBox1.Invoke(cb, new object[] { str });
}
else
{
str = str + "(" + System.DateTime.Now + ")";
if (this.listBox1.Items.Count > 26)
{
this.listBox1.Items.RemoveAt(0);
this.listBox1.Items.RemoveAt(0);
}
listBox1.Items.Add(str);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void M1()
{
try
{
//程序执行代码...
listView1.Items.Add("执行成功");
}
catch (Exception e)
{
listView1.Items.Add("异常:" + e.Message);
}
}
void WriteLog(string log, string filepath)
{
FileStream fs = new FileStream(filepath, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(log);
sw.Flush();
sw.Close();
fs.Close();
}