62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
</body>
</html>
using System;
using System.IO;
using System.Threading;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
var target = Server.MapPath("~/app_data/test.txt");
ThreadPool.QueueUserWorkItem(h =>
{
Thread.Sleep(10000);
File.WriteAllText(target, "写入数据_" + DateTime.Now.ToShortTimeString());
});
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "window.close();", true);
}
}
10秒钟之后,看看你的 text.txt 文件。