VB.net中同步多线程

时间:2012-01-21 14:28:03

标签: vb.net multithreading

    Using webClient = New System.Net.WebClient
        Dim owner = ""
        Try
            owner = webClient.DownloadString("http://" + CurrentBlog.Domain + "/test.php")
        Catch ex As Exception
        End Try
        appendToTextFile(CurrentBlog.Domain + checkdomainsowner(owner) + Microsoft.VisualBasic.vbNewLine, "gooddoorway.txt")
    End Using

我想使用threadpool运行它。

这样做的方法是

    Threading.ThreadPool.QueueUserWorkItem(
        Sub()
            Using webClient = New System.Net.WebClient
                Dim owner = ""
                Try
                    owner = webClient.DownloadString("http://" + CurrentBlog.Domain + "/test.php")
                Catch ex As Exception
                End Try
                appendToTextFile(CurrentBlog.Domain + checkdomainsowner(owner) + Microsoft.VisualBasic.vbNewLine, "gooddoorway.txt")
            End Using
        End Sub)

我希望appendToTextFile(CurrentBlog.Domain + checkdomainsowner(owner) + Microsoft.VisualBasic.vbNewLine, "gooddoorway.txt")与主线程同步。

这样做的简单方法是什么?我不想使用任何control.invoke,因为代码应该独立于任何控件运行。我不想使用全局变量,因为我的TA说这是件坏事。

0 个答案:

没有答案