简体   繁体   中英

C# Event handler Behavior

I have this code

List<DaSubscription> lstSubscription=new List<DaSubscription>();

for(int i=0;i<20;i++)//20 is just to simulate the behavior
{

    DaSubscription Generic=new DaSubscription();
    Generic.DataChanged += new DataChangedEventHandler(Generic_DataChanged);
    lstSubscription.add(Generic);
}

//EVENT Handler which is raised from a 3rd party library [COM]                 

void Generic_DataChanged(DaSubscription aDaSubscription, DaItem[] items, ValueQT[] values, int[] results)
{
   UpdateDataChangedDTO(items, values);
}

As the same event handler [m_daSubscription_Generic_DataChanged] is assigned to the multiple instance of same class [m_daSubscription]. Question i have is if at the same time multiple instances invokes this handler how will be handled here. will there will be any instance it shall overwrite the data. or the event handler will be separate for each instance.

The event handlers execute seperately. It sounds like your worried about the parameters being overwritten by another call to the handler. That won't happen (I don't think it is even possible). Since it doesn't look like you are accessing any shared objects in the event handler, you should be perfectly safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM