Polling for Asynchronous Call Completion : Async « Thread « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Thread » Async 
23.11.3.Polling for Asynchronous Call Completion
Imports System
    Imports System.Threading
    Imports System.Runtime.InteropServices 
    Public Class AsyncDemo 
        Public Function TestMethod(ByVal callDuration As Integer,<Out> ByRef threadId As IntegerAs 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
    Public Delegate Function AsyncMethodCaller(ByVal callDuration As Integer,<Out> ByRef threadId As IntegerAs String

    Public Class AsyncMain 
        Shared Sub Main() 
            Dim threadId As Integer

            Dim ad As New AsyncDemo()

            Dim caller As New AsyncMethodCaller(AddressOf ad.TestMethod)

            Dim result As IAsyncResult = caller.BeginInvoke(3000,threadId, Nothing, Nothing)

            While result.IsCompleted = False
                Thread.Sleep(50)
                Console.WriteLine(".")
            End While

            Dim returnValue As String = caller.EndInvoke(threadId, result)

            Console.WriteLine(threadId)
            Console.WriteLine(returnValue)
        End Sub
    End Class
23.11.Async
23.11.1.Waiting for an Asynchronous Call with WaitHandle
23.11.2.Waiting for an Asynchronous Call with EndInvoke
23.11.3.Polling for Asynchronous Call Completion
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.