Re: Why use Events?



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
> >> >> >> >>
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >>
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >
> >
>
>


.



Relevant Pages

  • Re: Why use Events?
    ... So the parent class can like declare the object WithEvents and hence the ... Suppose you have a custom message queue with thread synchronisation. ... So custom events are really very helpful. ... Can I create an event instead and put the while loop code ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Winter Madness - Passing Python objects as Strings
    ... But if you already have a queue, you may put other objects there (instead ... box really is that silly loop and the processor really is not fast at all. ... I thought of putting the string in a list, with the record type being the ... a socket, so it has to be a string. ...
    (comp.lang.python)
  • Re: OT: load distribution algorithm
    ... and hence its queue length becomes ... I realized I could eliminate the -1 flag value ... I also arbitrarily start the roundrobin with the worker holding the ... new socket arrives, the dispatcher always makes a simple choice. ...
    (comp.lang.tcl)
  • Re: Asynchronous Programming
    ... then started them one after another in a loop. ... .Net must be using fibers or something. ... >>>> socket per thread that reads N number of packets. ... >>>> could just stop it in TaskManager without a crash. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How Do I Use An SSLServerSocket With ServerSocketChannel?
    ... it's Java 5.0 or give up. ... endless loops of reading a socket and writing to the other one while ... loop and when it does a ServerSocket.accept, it goes into the inner loop ... isn't that going to steal a lot of CPU time ...
    (comp.lang.java.help)

Loading