Click here to Skip to main content
15,899,937 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Generalhelp~a codeDom segment Pin
noway5865-Sep-04 20:05
noway5865-Sep-04 20:05 
GeneralRe: help~a codeDom segment Pin
noway5865-Sep-04 20:08
noway5865-Sep-04 20:08 
GeneralPlease please help. Pin
Mega15-Sep-04 17:26
Mega15-Sep-04 17:26 
GeneralDatagrid ColumnHeader Captions Pin
beowulfagate5-Sep-04 15:42
beowulfagate5-Sep-04 15:42 
GeneralRe: Datagrid ColumnHeader Captions Pin
Anonymous6-Sep-04 8:14
Anonymous6-Sep-04 8:14 
Generalcreating a "please wait" dialog Pin
sagmam5-Sep-04 7:19
sagmam5-Sep-04 7:19 
GeneralRe: creating a "please wait" dialog Pin
Greg Eales6-Sep-04 2:02
Greg Eales6-Sep-04 2:02 
GeneralRe: creating a "please wait" dialog Pin
sagmam12-Sep-04 2:48
sagmam12-Sep-04 2:48 
I finally solved this thing with a solution that I like. Basically, I use the Observer Design Pattern to create an ObservedThread class.

In VB.NET, I implement this using events. The class has 2 events: Started and Ended.

The class is really simple:


' we can't derive from Thread so we use composition.
' Unfortunately, this means that we have to create the Thread
' interface in this class, but for this example, we'll only
' expose a Start method.

Imports System.Threading
Public Class ObservedThread

Protected Thread As Thread
Protected StartProc As ThreadStart

' some useful events:
Public Event StartedArgs(ByVal Thread As ObservedThread)
Public Event Started()
Public Event EndedArgs(ByVal Thread As ObservedThread)
Public Event Ended()

Public Sub New(ByVal StartProc As ThreadStart)
Me.StartProc = StartProc
Thread = New Thread(AddressOf ThreadProc)
End Sub

Protected Sub ThreadProc()
StartProc()
RaiseEvent EndedArgs(Me)
RaiseEvent Ended()
End Sub

Public Sub Start()
RaiseEvent Started()
RaiseEvent StartedArgs(Me)
Thread.Start()
End Sub
End Class



And let's assume you have an independent form, that you want to appear while the thread executes, and close when the thread finishes. The form has nothing to do with the thread. It's a simple form, that has a timer ticking every few millisecs:

dim frm as New frmPleaseWait
Dim th As New ObservedThread(AddressOf DoSomethingHeavy)
AddHandler th.Started, AddressOf frm.Show
AddHandler th.Ended, AddressOf frm.Close
th.Start()

That's it. Works great.



/=/=/=/= Sagmam =\=\=\=\
GeneralRe: creating a "please wait" dialog Pin
jonathan156-Sep-04 4:27
jonathan156-Sep-04 4:27 
GeneralConnecting to SQL Server DB Pin
RamBhatt5-Sep-04 4:13
RamBhatt5-Sep-04 4:13 
GeneralRe: Connecting to SQL Server DB Pin
Mekong River5-Sep-04 7:27
Mekong River5-Sep-04 7:27 
GeneralRe: Connecting to SQL Server DB Pin
RamBhatt5-Sep-04 20:03
RamBhatt5-Sep-04 20:03 
GeneralRe: Connecting to SQL Server DB Pin
jonathan156-Sep-04 4:38
jonathan156-Sep-04 4:38 
GeneralRe: Connecting to SQL Server DB Pin
Mekong River6-Sep-04 5:11
Mekong River6-Sep-04 5:11 
Generalsuccess Pin
RamBhatt6-Sep-04 18:25
RamBhatt6-Sep-04 18:25 
GeneralRe: success Pin
Mekong River7-Sep-04 21:42
Mekong River7-Sep-04 21:42 
GeneralRe: success Pin
RamBhatt8-Sep-04 3:44
RamBhatt8-Sep-04 3:44 
QuestionHow to use Pin
Murtuza Husain Miyan Patel5-Sep-04 4:08
professionalMurtuza Husain Miyan Patel5-Sep-04 4:08 
AnswerRe: How to use Pin
Mekong River5-Sep-04 7:22
Mekong River5-Sep-04 7:22 
GeneralDeleting contents of history folder Pin
nitin_ion4-Sep-04 0:33
nitin_ion4-Sep-04 0:33 
GeneralRe: Deleting contents of history folder Pin
Mekong River6-Sep-04 5:28
Mekong River6-Sep-04 5:28 
GeneralRe: Deleting contents of history folder Pin
nitin_ion6-Sep-04 19:00
nitin_ion6-Sep-04 19:00 
GeneralRe: Deleting contents of history folder Pin
Mekong River6-Sep-04 21:31
Mekong River6-Sep-04 21:31 
GeneralText color on forms Pin
Kevnar3-Sep-04 21:17
Kevnar3-Sep-04 21:17 
GeneralCrystal Report 9 + VB6 Pin
spn3-Sep-04 20:37
spn3-Sep-04 20:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.