Raise event or return structure??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dann

    #1

    Raise event or return structure??

    VB.Net 2005:

    I have a class that performs some functions and then needs to update
    some labels on the main form (from which it is called) with several
    pieces of information, some text, some datetime etc, according to the
    results of the calculations.

    I can see at least a couple of ways of doing this:

    1. Define a structure that contains all the items of information that
    I need to pass back and assign a variable with this structure as the
    return value to the calling routine in the main form. (Assuming I can
    do this.)

    2. Raise a custom event in the client class that passes the required
    data items as separate arguments. Monitor this event in the main form
    and update the form labels whenever the event is raised.

    Any views on which of these options might be preferred (or any other
    alternatives?

    JGD
  • Marina Levit [MVP]

    #2
    Re: Raise event or return structure??

    Either way, you are going to end up populating some sort of class or
    structure - either as the return value, or as a custom EventArgs class.

    The question really is if this method is the only time these values can
    change, and conceptually how these values can change.

    Sometimes an event feels right, because something is changing, and you want
    to raise an event to notify any listeners. If there are several ways that
    something can change, this makes even more sense.

    However, if the function is ComputeLabelVal ues - then that function should
    return the label values it computed as the return value. And nothing else
    would ever change these values, so that is fine.

    "John Dann" <news@prodata.c o.uk> wrote in message
    news:rrdt829c7n uupn9eru9rtf4oe 7ti1pn6jr@4ax.c om...[color=blue]
    > VB.Net 2005:
    >
    > I have a class that performs some functions and then needs to update
    > some labels on the main form (from which it is called) with several
    > pieces of information, some text, some datetime etc, according to the
    > results of the calculations.
    >
    > I can see at least a couple of ways of doing this:
    >
    > 1. Define a structure that contains all the items of information that
    > I need to pass back and assign a variable with this structure as the
    > return value to the calling routine in the main form. (Assuming I can
    > do this.)
    >
    > 2. Raise a custom event in the client class that passes the required
    > data items as separate arguments. Monitor this event in the main form
    > and update the form labels whenever the event is raised.
    >
    > Any views on which of these options might be preferred (or any other
    > alternatives?
    >
    > JGD[/color]


    Comment

    Working...