Priority Order with methods?

Say I have 2 methods. One of them is a method called by changing the selected index in the list. The second method helps by clearing all text fields, setting the list index to -1 and setting the focus.

Question:

The second method is executed, during the code it changes the selected index of the list to -1, thereby setting an event trigger for the first method. Method 2 HALT executes its own execution and passes the process to the event, and then returns to its work after method 1 is finished ... OR has the whole method 2 not completed its entire code block, and then switched to method 1 after changing the selected index?

+3
source share
5 answers

The first case.

, , .

, . , . , , . , , , . *

, , , . ( " " .) , , , . , , , .

, , "invoke index-changed event handler". , (, ), "set the index" .

, - , . , . ( !) , , , , , .

* , , . , .

+8

, : ! , 2 . # Windows Forms .

: threading.

, .

+1

, , . , , .NET, Il. ILDASM Reflector . IL , , , .

" ", . , , " ", .

+1

, #, , . ( , , ), , ( ). () , .

: , , , . , , , GUI .

, :)

0

, , . Method2 , , , Method1 , Method2 .

, Method1, - : ( )

Method2(object sender, System.EventArgs e)
{
  //Unsubscribe Method1 from ListboxEvent
  Listbox.OnSelectionChange -= Method1;

  ... Stuff Method2 actually does ...

  Manualy call Method1 if you want it to fire

  //Subscribe Method1 from ListboxEvent
  Listbox.OnSelectionChange += Method1;
}

This is probably not optimal (and maybe some recommendations), but due to the lack of a better explanation, at least you have some information to help you perform the search. Hope this helps!

0
source

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


All Articles