如何通过线程为标签设置值?

时间:2011-11-28 10:11:24

标签: asp.net

此代码提供错误'对象引用未设置为对象的实例'。

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";
    }

1 个答案:

答案 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 CodePageAsyncTask.