File: WinWebAsyncDemo.VB.Txt Date: 7/29/04 By: Dan Garlen, MCT MCT04@Garlen.Net --------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- WinWebAsyncDemo --------------------------------------------------------------------------------------- AsyncWebService Imports System.Threading Imports System.Web.Services _ Public Function Delay(ByVal intDelay As Integer) As String Dim intSeconds As Long = intDelay * 1000 Thread.CurrentThread.Sleep(intSeconds) Return Now.ToLongTimeString & ": " & "Delay Complete" End Function --------------------------------------------------------------------------------------- WinClient Imports System.Threading Public Class DemoClient Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " lblSubmit lstResults btnAnotherEvent txtAnotherActivity txtAnotherActivity btnGetBusy #End Region Dim AsyncCallbackItsDone As New AsyncCallback(AddressOf ItsDone) Private Sub Post(ByVal strMessage As String) lstResults.Items.Add(Now.ToLongTimeString & ": " & strMessage) End Sub Private Sub lblSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSubmit.Click Post("Top of Button Routine") Const intDelayTime As Integer = 10 Post("Delay Time = " & intDelayTime.ToString) Dim ws As New localhost.AsyncService ' Sync Method : ' ws.Delay(intDelayTime) ' ' Open-loop ASync(Method 1) : 'Dim Result As IAsyncResult = ws.BeginDelay(intDelayTime, _ ' Nothing, Nothing) ' ' Closed-loop ASync(Method 2) : ' Dim Result As IAsyncResult = ws.BeginDelay(intDelayTime, _ ' AddressOf ItsDone, Nothing) '' Work in process... Closed-loop ASync(Method 3 using AsyncCallback) : 'Dim Result As IAsyncResult = ws.BeginDelay(intDelayTime, _ ' AsyncCallbackItsDone, Nothing) Post("Bottom of Button Routine") 'Post("IAsyncResult.IsComplete = " & Result.IsCompleted.ToString) End Sub Private Sub ItsDone(ByVal Result As IAsyncResult) ' This will be fired by the Web Service Post("Callback Routine") Me.Update() End Sub Private Sub btnAnotherEvent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnotherEvent.Click Post("Another Event...") End Sub Private Sub txtAnotherActivity_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAnotherActivity.TextChanged Me.Text = txtAnotherActivity.Text End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click txtAnotherActivity.Text = "" End Sub Private Sub btnGetBusy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetBusy.Click Post("Top of Get Busy Routine") Me.Update() Thread.CurrentThread.Sleep(20000) Post("Bottom of Get Busy Routine") Me.Update() End Sub Private Sub GetBusy1() Dim i, j As Integer For i = 1 To 1000 i = 1 For j = 0 To 9 txtAnotherActivity.Text &= j.ToString("0") Next txtAnotherActivity.Text = "" Next End Sub