One common event name or multiple descriptive events

You would do:

this.btSomeButton.Click += btSomeButton_OnClick;

private void btSomeButton_OnClick(object sender, EventArgs e)
{
    this.DoFunc1();
    this.DoFunc2();
}

Or:

this.btSomeButton.Click += DoFunc1;
this.btSomeButton.Click += DoDunc2;

Are there any hidden implications for using the second method? How, is it guaranteed that DoFunc2 () will be launched after DoFunc1 ()?

+3
source share
6 answers

I think the first method is safer.

AFAIK there is no guarantee when it comes to the execution order of a method, and if the methods actually arrive in sequential order, the first method makes more sense.

In addition, when multiple event handlers are attached to an event, it is very easy to skip other events when detaching individual event handlers.

+2
source

I would do the first too.

Perfomance , # 1 imho - , . , :

this.btSomeButton.Click += DoSomethingRelatedToDataPersistence;
this.btSomeButton.Click += DoSomethingRelatedToTheDirectionTheMoonSpinsAroundTheEarth;

.. , : P

2 ( ), . , .

imho. " , " - .

0

, , , . , .

0

.

, ( ) :

  • DoFunc1 DoFunc2 .
  • ( ..).
  • DoFunc1 DoFunc2 .
  • DoFunc1 DoFunc2 .
  • , .
  • DoFunc1 DoFunc2 , .
  • , DoFunc1 DoFunc2 .

, , . , # .

0

, . . ...

MulticastDelegate , , . , , .

, , .

, , ...

this.btSomeButton.Click += (sender, args)
{
  this.doFunc1();
  this.doFunc2();
};
0

() .

. , , - , , , , .

, , . , , func1() func2() , , , , (, , ).

0

Source: https://habr.com/ru/post/1706269/


All Articles