Re: Delegates and Classes
- From: Dave <Dave@xxxxxxxxxx>
- Date: Wed, 03 Jan 2007 12:05:55 -0500
I have attached a copy of the code at module end:
Module modSystemMonitor
Public Delegate Sub MyDelegate(ByVal intIndex As Integer)
Public frmOver As frmOverview
Public colSystem As New Collection
Public MyDel As MyDelegate
Public Sub LoadSystemId()
Dim n As Integer
Dim Dave As clsSystem
MyDel = AddressOf MyDelegateSub
n = 1
Dave = New clsSystem("Local Test", "Local Test", "WSDEV",
"MONITOR")
AddHandler Dave.DataAvailableEvent, AddressOf
colSystem_NewDataAvailable
Dave.Index = n
colSystem.Add(Dave, Dave.SystemID)
n = 2
Dave = New clsSystem("Backup Domain Controller", "Backup Domain
Controller", "MSS06", "MONITOR")
AddHandler Dave.DataAvailableEvent, AddressOf
colSystem_NewDataAvailable
Dave.Index = n
colSystem.Add(Dave, Dave.SystemID)
End Sub
'*********************************
Public Sub MyDelegateSub(ByVal intIndex As Integer)
frmOver.Label2.Text = "Testing123|" & intIndex
'*** <<This is where I get the Error Cross-Thread Operation Not Valid:
Control 'Label2' accessed form a thread other than the thread it was
created in >> *****
End Sub
'*********************************
Private Sub colSystem_NewDataAvailable(ByVal intIndex As Integer)
Dim Dave As New Data.DataTable
Try
MyDel.Invoke(intIndex)
MsgBox(intIndex)
Catch
MsgBox(Err.Description)
End Try
End Sub
End Module
On Wed, 03 Jan 2007 09:22:52 -0500, Dave <Dave@xxxxxxxxxx> wrote:
Good morning,.
I have a class that must trigger an event in a module, which will in
turn update a Label on a form. Due to being in a seperate thread,I
must use a delegate.
Now here is my question. I have managed to create a delegate on a
Form using the Invoke method. In this case though, the class is
actually created as a global variable and it's instance is created in
a module.
What is the best way to implement this delegate since I can't perform
an Invoke from a module?
Thanks for the help,
Dave
- Follow-Ups:
- Re: Delegates and Classes
- From: Herfried K. Wagner [MVP]
- Re: Delegates and Classes
- References:
- Delegates and Classes
- From: Dave
- Delegates and Classes
- Prev by Date: Re: Cannot add microsoft.visualbasic as reference - newbie ?
- Next by Date: Re: ListBox not working?!
- Previous by thread: Delegates and Classes
- Next by thread: Re: Delegates and Classes
- Index(es):
Relevant Pages
|