Synchronous Events?

  • Thread starter Thread starter CJ Taylor
  • Start date Start date
C

CJ Taylor

I don't know how to do this persay, but maybe someone could give me a little
guidance.

I will start with an example, if you've ever heard of ComponentOne they have
a tool called DataObjects, this thing raises events many times, however, you
can modify data in the event args which is then passed back to the caller (I
don't really understand how because the events are declared ByVal).

Thats beside the point, but it appears to be synchronous (i.e. it waits for
a result to come back from the event handler.)

Anyone know how I can do this?

Thanks,
CJ
 
I don't know how to do this persay, but maybe someone could give me a little
guidance.

I will start with an example, if you've ever heard of ComponentOne they have
a tool called DataObjects, this thing raises events many times, however, you
can modify data in the event args which is then passed back to the caller (I
don't really understand how because the events are declared ByVal).

Because an Event arg is a reference type. Passing ByVal in this case
says to pass the referenc by value. That means you can still modify the
object..
Thats beside the point, but it appears to be synchronous (i.e. it waits for
a result to come back from the event handler.)

Anyone know how I can do this?

Events are syncronous by default. You have to work at it to do it async
:) So, your already where you want to be...
 
Tom,

Because an Event arg is a reference type. Passing ByVal in this case
says to pass the referenc by value. That means you can still modify the
object..

So I raise the event, everything that is hooked into it gets a message that
its been fired and my code that handles it fires. Your saying, no matter
what I can go ahead and modify my event args (given they are not read only)
and when it gets back from the Raise in the calling class, the modified
values will be there? (Basically, they are getting a copy of the values
that are located in the reference variable?)

Do I understand you correct?

So... further going on that, I should actually have to do nothing in order
for the two to work together as I expect, correct?

Thanks,
CJ
 
Tom,



So I raise the event, everything that is hooked into it gets a message that
its been fired and my code that handles it fires. Your saying, no matter
what I can go ahead and modify my event args (given they are not read only)
and when it gets back from the Raise in the calling class, the modified
values will be there? (Basically, they are getting a copy of the values
that are located in the reference variable?)

Do I understand you correct?

Pretty much.
So... further going on that, I should actually have to do nothing in order
for the two to work together as I expect, correct?

In most cases, yes. Now, if you pass a value type in you event
arguments then all bets are off, because a copy will get made. If you
use a reference type with properties, then yes - you don't have to do
anything special.
 
Back
Top