Asp.net BackgroundWorker(非同步執行)

非同步執行

順便結合前篇的委派

Webform & Winform 皆可使用如下方式達到非同步執行

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        AddHandler mythread.DoWork, AddressOf sub_WorkStart
        AddHandler mythread.RunWorkerCompleted, AddressOf sub_Workcomplete
    End Sub

    Sub sub_WorkStart(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
        Response.Write("我")
    End Sub
    Sub sub_Workcomplete(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs)
        Response.Write("妳")
    End Sub



    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        mythread.RunWorkerAsync()
        mythread.Dispose()
    End Sub