Re: Thread A notifying Thread B of an Event
From: CJ Taylor (nospam_at_blowgoats.com)
Date: 02/20/04
- Next message: Francisco: "Re: flatstyle setting across all app change..."
- Previous message: Matt: "External Window Location - Multi Monitor"
- In reply to: Bob Day: "Thread A notifying Thread B of an Event"
- Next in thread: Bob Day: "Re: Thread A notifying Thread B of an Event"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 20 Feb 2004 13:51:56 -0600
"Bob Day" <BobDay@TouchTalk.net> wrote in message
news:ubnnMT%239DHA.1504@TK2MSFTNGP12.phx.gbl...
> Using VS 2003, VB, MSDE...
>
> There are two threads, A & B, that continously run and are started by Sub
> Main. They instantiationsl of identical code. Thread A handles call
> activity on telephone line 1 and Thread B handles call activity on
telephone
> line 2. They use a common SQL datasource, but all DataSets are unique to
> each thread.
>
> Is there a way for thread A to occasionally communication to thread B that
> something has happened? The ideal situation would be for thread A to
raise
> an event that a handler in thread B handles. But, I don't see how to do
> that (the raised event would be handled "up the call stack" in Sub Main,
not
> "horizontially" by the other thread).
>
You can use addhandler... If you remember from your thread creation you
have something like
Dim ThreadA as new System.Threading.thread(AddressOf myClass.MyFunctionA)
Dim ThreadB as new System.Threading.Thread(AddressOf myClass.MyFunctionB)
now these act like any other class... Which means you can raisevents and
hook between threads (a lot of us design this way, how do you think we make
data intensive UI's so damn quick.=))
So, all those events in A are availible in B through your class
declaration... say classA has eventA and classB has eventB...
So.. lets try this.
sub main()
dim classA as new myClassA
dim classB as new myClassB
AddHandler classA.eventA, New EventHandler(AddressOf classB.onEventA)
...thread starting...
end sub
ClassB.onEventA is a matching eventhandler to the class A event (I just
used an argumentless event handler delegate (thats what EventHandler is...)
Delegates ensure communication across threads... (one of there many useful
purposes)
And thats about it...
HTH,
CJ
> Specifically, thread A has added a row(s) to the common datasource that I
> need thread B to know about. I am currently doing it with a timer in
thread
> B that check the common datasource for changes every 15 seconds, which
works
> OK, but am looking for a simpler solution. I have looked at SQL
triggers,
> but don't see how that would alert thread B. I have looked at RaseEvents,
> but don't see any help there either.
>
> Any ideas? Do System.Timers. exert a heavy resource usage toll? If not I
> may jus stick with the timer method.
>
> Thansk!
>
> Bob
>
>
- Next message: Francisco: "Re: flatstyle setting across all app change..."
- Previous message: Matt: "External Window Location - Multi Monitor"
- In reply to: Bob Day: "Thread A notifying Thread B of an Event"
- Next in thread: Bob Day: "Re: Thread A notifying Thread B of an Event"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|