Re: Why use Events?
- From: "rawCoder" <rawCoder@xxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 18:57:28 +0500
Sorry for late reply,.
The events can be anything like DataReceived, DataSent, Connected,
Disconnected.
Have you seen the VB6 Winsock control.
That might help you grasp the idea of an encapsulated socket module based on
event.
HTH
rawCoder
"Brett" <no@xxxxxxxx> wrote in message
news:OZEkV3dQFHA.3076@xxxxxxxxxxxxxxxxxxxxxxx
> I'm understanding it better. Staying with the socket example, which event
> is your handler listening for?
>
> Can you possibly post some psuedo code?
>
> Thanks,
> Brett
>
> "rawCoder" <rawCoder@xxxxxxxxxxx> wrote in message
> news:uHgVLcdQFHA.356@xxxxxxxxxxxxxxxxxxxxxxx
> > Hi Brett,
> >
> > I have a class that handles all the Socket related stuff and receives
> > data.
> > Now when some data is received it RAISES an EVENT so that the parent
class
> > knows there was some data received.
> > So the parent class can like declare the object WithEvents and hence the
> > class implementing Socket operations doesnt need to know how to process
> > the
> > data or the business logic while the parent class handles it.
> >
> > Suppose you have a custom message queue with thread synchronisation.
> > Now if the queue has an event that gets raised at appropraite time when
> > some
> > thing is added in it,
> > Then the caller doesnt need to do all the plumbing related to DeQueuing.
> > All it needs to do is declare the queue object and handle the data added
> > event.
> >
> > One more way events are very very useful is for inter modular
> > communication
> > as specified by someone else already in the thread.
> > Suppose you have a class 'E' which has one event declared in it and one
> > public method that raises the event.
> > Now class A has an instance of class E and calls the public mehtod which
> > raises the event.
> > Another Class B which also has the instance and handles the event, gets
> > the
> > notification and the data associated.
> > The beauty is that the class 'E' never knew anything about 'A' or 'B'
> >
> > Hope this makes sense to you more in terms of possible implementations
> > where
> > custom events can be used.
> > I have implemented one way or another these scenarios in more or else
the
> > same way.
> > So custom events are really very helpful.
> >
> > Let us know what exaclty is your confusion now ?
> >
> > HTH
> > rawCoder
> >
> > "Brett" <no@xxxxxxxx> wrote in message
> > news:%23ssG4NcQFHA.2788@xxxxxxxxxxxxxxxxxxxxxxx
> >> I understand the form events because of user action but even with all
of
> > the
> >> post to my thread, I still have a difficult time seeing where I would
use
> > a
> >> custom event.
> >>
> >> Perhaps relating it to something I'm working on will help. I use a
while
> >> loop with tcpclient and check if
> >> networkStream = tcpClient.GetStream()
> >> has anything. Can I create an event instead and put the while loop
code
> > in
> >> it?
> >>
> >> Thanks,
> >> Brett
> >>
> >> "Dennis" <Dennis@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >> news:8083C84D-D9E8-4DB3-921B-311CCF0397B1@xxxxxxxxxxxxxxxx
> >> > You are correct..you can write an application with a big while or do
> > loop
> >> > and
> >> > get input from the user then branch to different subs, funcitons,
> > methods,
> >> > etc. That's what the original basic programming language did.
> >> > However,
> >> > events will make your programming life much easier and more flexible
if
> >> > you
> >> > take the time to learn how to use them.
> >> >
> >> > "Brett" wrote:
> >> >
> >> >>
> >> >> "Peter Proost" <pproost@xxxxxxxxxxxxxxxxxx> wrote in message
> >> >> news:%23RB%23$BQQFHA.2520@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> > Hi, I use them in usercontrols for example I've got a usercontrol
> > with
> >> >> > a
> >> >> > combobox on it and some more controls.
> >> >> > The combobox is filled with customers, and when I choose one the
> > other
> >> >> > controls on the usercontrol get filled but I also want to notify
the
> >> >> > form
> >> >> > where my usercontrol is on. So in my usercontrol I code:
> >> >> >
> >> >> > Public Event Customer(ByVal CustomerName as String)
> >> >> >
> >> >> > and then when the comboxs' selectedindex changes I call my event
> >> >> > like
> >> >> > this
> >> >> > RaiseEvent Customer("MyCustomerName")
> >> >>
> >> >> But you could do a class Customer() method call here as well. What's
> > the
> >> >> difference?
> >> >>
> >> >> >
> >> >> > Next, on the form where the usercontrol is placed I can select the
> >> >> > usercontrol in the code editor (left combo) and select it's event
> >> >> > Customer
> >> >> > (right combo) and I get something like this and can set my
form.text
> > to
> >> >> > the
> >> >> > CustomerName
> >> >> >
> >> >> > Private Sub UserControl1_Customer(ByVal CustomerName As String)
> > Handles
> >> >> > UserControl1.Customer
> >> >> > me.Text = CustomerName
> >> >> > end sub
> >> >> >
> >> >> > hth Peter
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > "Brett" <no@xxxxxxxx> schreef in bericht
> >> >> > news:#arf62PQFHA.1528@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> >>
> >> >> >> "rawCoder" <rawCoder@xxxxxxxxxxx> wrote in message
> >> >> >> news:%235kvvsPQFHA.648@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> >> > The way I use them ususally.
> >> >> >> >
> >> >> >> > Events are for intimation.
> >> >> >> >
> >> >> >> > An Object intimating a class for some event.
> >> >> >> >
> >> >> >> > You cant by regular means call a method of the class that has
> >> >> > instantiated
> >> >> >> > the object from within the object.
> >> >> >>
> >> >> >> Can you show a code example of what you mean here?
> >> >> >>
> >> >> >> > Events help in this case and make life easy.
> >> >> >> >
> >> >> >> > HTH
> >> >> >> > rawCoder
> >> >> >> >
> >> >> >> > "Brett" <no@xxxxxxxx> wrote in message
> >> >> >> > news:usL8eVPQFHA.1476@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> >> >> What are reasons to create your own events? Why not just call
a
> >> >> >> >> class
> >> >> >> >> method/function instead?
> >> >> >> >>
> >> >> >> >> Thanks,
> >> >> >> >> Brett
> >> >> >> >>
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >>
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >
> >
>
>
.
- References:
- Why use Events?
- From: Brett
- Re: Why use Events?
- From: rawCoder
- Re: Why use Events?
- From: Brett
- Re: Why use Events?
- From: Peter Proost
- Re: Why use Events?
- From: Brett
- Re: Why use Events?
- From: Dennis
- Re: Why use Events?
- From: Brett
- Re: Why use Events?
- From: rawCoder
- Re: Why use Events?
- From: Brett
- Why use Events?
- Prev by Date: Re: datatable already belongs to another dataset
- Next by Date: Re: Removal of a service
- Previous by thread: Re: Why use Events?
- Next by thread: Why use Events?
- Index(es):
Relevant Pages
|
Loading