Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / Windows Forms

AsyncWorker - A Typesafe BackgroundWorker (and about Threading in General)

Rate me:
Please Sign up or sign in to vote.
4.76/5 (23 votes)
11 Apr 2010CPOL9 min read 58.4K   1.8K   93  
Generic methods enable typesafe Threading
Imports System.Windows.Forms

Partial Public Class uclCountDown : Inherits UserControl

   Private WithEvents _CountDown As New CountDown()

   Public Sub New()
      InitializeComponent()
      ckIsRunning.DataBindings.Add( _
         "Checked", _CountDown, "IsRunning", False, DataSourceUpdateMode.OnPropertyChanged)
   End Sub

   Private Sub _CountDown_Tick(ByVal sender As Object, ByVal e As CountDown.TickEventargs) _
         Handles _CountDown.Tick
      label1.Text = e.Counter.ToString()
      If e.Counter = 0 Then
         MessageBox.Show("Go!")
      End If
   End Sub

   Private Sub ckIsRunning_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) _
         Handles ckIsRunning.CheckedChanged
      If ckIsRunning.Checked Then _CountDown.Start(CInt(udInitValue.Value))
   End Sub

   Private Sub uclCountDown_Disposed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Disposed
      _CountDown.Dispose()
   End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions