当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET AsyncResult.IsCompleted属性代码示例

本文整理汇总了VB.NET中System.Runtime.Remoting.Messaging.AsyncResult.IsCompleted属性的典型用法代码示例。如果您正苦于以下问题:VB.NET AsyncResult.IsCompleted属性的具体用法?VB.NET AsyncResult.IsCompleted怎么用?VB.NET AsyncResult.IsCompleted使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Runtime.Remoting.Messaging.AsyncResult的用法示例。


在下文中一共展示了AsyncResult.IsCompleted属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: TestMethod

' 导入命名空间
Imports System.Threading
Imports System.Runtime.InteropServices 

Namespace Examples.AdvancedProgramming.AsynchronousOperations
    Public Class AsyncDemo 
        ' The method to be executed asynchronously.
        Public Function TestMethod(ByVal callDuration As Integer, _
                <Out> ByRef threadId As Integer) As String
            Console.WriteLine("Test method begins.")
            Thread.Sleep(callDuration)
            threadId = Thread.CurrentThread.ManagedThreadId()
            return String.Format("My call time was {0}.", callDuration.ToString())
        End Function
    End Class

    ' The delegate must have the same signature as the method
    ' it will call asynchronously.
    Public Delegate Function AsyncMethodCaller(ByVal callDuration As Integer, _
        <Out> ByRef threadId As Integer) As String
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Runtime.Remoting.Messaging,代码行数:21,代码来源:AsyncResult.IsCompleted

示例2: Main

' 导入命名空间
Imports System.Threading
Imports System.Runtime.InteropServices 

Namespace Examples.AdvancedProgramming.AsynchronousOperations

    Public Class AsyncMain 
        Shared Sub Main() 
            ' The asynchronous method puts the thread id here.
            Dim threadId As Integer

            ' Create an instance of the test class.
            Dim ad As New AsyncDemo()

            ' Create the delegate.
            Dim caller As New AsyncMethodCaller(AddressOf ad.TestMethod)
       
            ' Initiate the asynchronous call.
            Dim result As IAsyncResult = caller.BeginInvoke(3000, _
                threadId, Nothing, Nothing)

            ' Poll while simulating work.
            While result.IsCompleted = False
                Thread.Sleep(250)
                Console.Write(".")
            End While

            ' Call EndInvoke to retrieve the results.
            Dim returnValue As String = caller.EndInvoke(threadId, result)

            Console.WriteLine(vbCrLf & _
                "The call executed on thread {0}, with return value ""{1}"".", _
                threadId, returnValue)
        End Sub
    End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Runtime.Remoting.Messaging,代码行数:36,代码来源:AsyncResult.IsCompleted

输出:

Test method begins.
.............
The call executed on thread 3, with return value "My call time was 3000.".


注:本文中的System.Runtime.Remoting.Messaging.AsyncResult.IsCompleted属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。