Firing Events from Modile containing a Threads code

G

Guest

Hi

Ive been advised to use events in my app. I have a worker thread that listens for UDP packets. It converts the incoming UDP Byte array into a Packet object. This then gets placed onto a ReceivedPackets Queue. Im not too familiar with Events but need to know how to get my thread to fire the event and my form, could 1 of 9 forms, to detect that event has been fired and handle it

I know that I should use "RaiseEvent" in the Thread. The thread has been declared in a Module. How do I put it all together? I guess the forms need something like "AddHandler EventName, New EventHandler Addressof procedureToRun" but donr know how to put it all together. I tried but the Thread was complaining of an "End of statement expected" compilor error

Also, If Ive received 2 packets with a 200ms interval between them and hence the event gets fired twice, what happens? does the app wait for the first procedure to finish executing and then call the method again in response to the second event firing? Can this cause potential delay/problems in my app

Im using VB.NET but C# will suffice

Thanks.
 
C

Chris Tacke, eMVP

Take a look at this:

http://www.codeproject.com/vb/net/StepByStepEventsInVBNET.asp

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



James Anderson said:
Hi,

Ive been advised to use events in my app. I have a worker thread that
listens for UDP packets. It converts the incoming UDP Byte array into a
Packet object. This then gets placed onto a ReceivedPackets Queue. Im not
too familiar with Events but need to know how to get my thread to fire the
event and my form, could 1 of 9 forms, to detect that event has been fired
and handle it.
I know that I should use "RaiseEvent" in the Thread. The thread has been
declared in a Module. How do I put it all together? I guess the forms need
something like "AddHandler EventName, New EventHandler Addressof
procedureToRun" but donr know how to put it all together. I tried but the
Thread was complaining of an "End of statement expected" compilor error.
Also, If Ive received 2 packets with a 200ms interval between them and
hence the event gets fired twice, what happens? does the app wait for the
first procedure to finish executing and then call the method again in
response to the second event firing? Can this cause potential delay/problems
in my app?
 
C

Chris Tacke, eMVP

I've got no idea how VB used Modules. Logically they make no sense to me,
as they don't seem to reside inside any particular class. Personally I'd
move the code to a class and make it static (Shared) if necessary. I think
that's probably all a Module is doing anyway.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



James Anderson said:
Thanks Chris,

But the article doesnt mention anything about raising events from Modules.
I have a method that is declared in a module and is run in a thread
(listenForUDPPackets). I want to fire an event from the method in the Thread
and the form can handle it. Any Ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top