您的位置:首页 > 其它

BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题

2015-03-06 19:55 405 查看
Public Delegate Function ParallelEvent() As Boolean

       '並列処理で行う
        Dim waitHandleList As New List(Of WaitHandle)

        For Each procedure As CSVLoadProcedure In _procedureList
            Dim parallelEvent As ParallelEvent = New ParallelEvent(AddressOf procedure.CSVFieldCheckByConv)
            Dim iAsyncResult As IAsyncResult = parallelEvent.BeginInvoke(Nothing, Nothing)
            If Not parallelEvent.EndInvoke(iAsyncResult) Then
                If Not procedure.LoadException Is Nothing Then
                    WriteSystemErrorLog(procedure.LoadException)
                End If
                Return
            End If

            waitHandleList.Add(iAsyncResult.AsyncWaitHandle)
        Next

        'すべての処理が終了するまで待機()
        WaitHandle.WaitAll(waitHandleList.ToArray())

        If ExceptionExists() Then Throw New CRGaugeException("CSVFieldCheck")

    End Sub


参考

http://www.cnblogs.com/sufei/p/3140557.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐