此代码提供错误'对象引用未设置为对象的实例'。
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
_Default obj = new _Default();
Thread thread = new Thread(new ThreadStart(obj.ThreadStart));
thread.Start();
}
public void ThreadStart()
{
show();
}
private void show()
{
lblget.Text = "hi";
}
答案 0 :(得分:1)
无需创建_Default的实例。
protected void Page_Load(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
private void show()
{
lblget.Text = "hi";
}
阅读这些文章 - Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code和PageAsyncTask.