execution of events

  • Thread starter Thread starter Jesper
  • Start date Start date
J

Jesper

Hi,

Background.
In an engineering application I consider using events to
control the flow in the program under the following
philosophy: When a value X change it fires a "i'm
changed" event. A value Y will is a function of X and
will therefore subscribe to X-changed event. Y will
recalculate and fire its own "i'm changed" in order for
other values dependent on Y to recalculate. This would be
a good solution to the nature of my project.


Like

A = 5
Fire A chaged

capture A Changed
B = 5 * A
fire B changed

capture B changed
C = B*B


I have the following question:
Is the firing of an event equal to call a procedure, i.e.
will the execution immediately go a subscriber of the
event and then return or will it start a new thread.

best regards Jesper.
 
Hi Jesper,
You can do either. If you declare an event and call the event as a normal
method it will execute the event in the same thread and it will be just like
calling a procedure. If you want to execute the event handler in a separate
thread you can use delegate's (in this case event's) BeginInvoke and
EndInvoke methods.

for example if you have an event ValueChanged:

public event EventHandler ValueChanged;

if you do:
ValueChanged(this, EventArgs.Empty);
this will execute any event handler in the same thread as a normal
procedure.

if you do:
ValueChanged.BeginInvoke(......) ;
this will start the event handlers in a separate thread from the thread pool

HTH
B\rgds
100;
 
Back
Top