Raise event or return structure??

J

John Dann

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
 
M

Marina Levit [MVP]

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

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