如何使用listBox创建日志

时间:2015-07-23 10:52:59

标签: c# asp.net listbox

我正在使用visual stdio 2008在c#中创建一个webapp。

在页面中有一个按钮,可以开始很长时间(约1分钟)的处理。 在此期间,我想在同一页面的列表框中显示程序正在执行的操作,但我不知道如何执行此操作,因为进程启动页面时不断刷新,因此即使在代码中列表框也始终为空有很多ListBox.Items.Add("..")

希望你能帮助我。 (p.s.抱歉我的英文不好,我是意大利人)

1 个答案:

答案 0 :(得分:-1)

由于其他原因,您的页面加载可能需要时间,但不确定。

public static void WriteLog(string Error)
{
    using (StreamWriter logfile = new StreamWriter(filePath + "Log.txt", true))
    {
        logfile.WriteLine(DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString() + " -@: " + Error);
        logfile.Close();
    }

}

使用此功能记录。

在Page load

中调用此函数
WriteLog("Comments");