c# - Suspend .Net Event Listener during Update -


i have usercontrol in i've put dropdown combobox , datagridview.

the combobox filter containing items depending of data in datagridview. objects in datagridview have property called producttype. every producttype in datagridview, combobox filter adds filter option.

the datagridview needs refreshed when following events occur:

  • datagridview_load
  • combobox_selecteditemchanged
  • refreshbutton_clicked

the combobox reinitialised when refresh data grid, since list of producttype present in grid might've change.

the problem when click refresh button, refresh function gets called multiple times. clicking refresh button triggers refreshbutton_clicked. refresh reinitialise combobox. reinitialising combobox triggers combobox_selecteditemchanged since selected item no longer same. have put item selected prior refresh, combobox_selecteditemchanged triggered. etc.

is there way suspend event listener while refresh , resume afterwards ?

you use bool _isrefreshing; indicate you're in process.

the refresh button "hiding" action seems code smell, me. it's preferable subscriber decide when should or should not carry out method.

if (!_isrefreshing) 

the reality event is happening, disabling listener obscures reality... if there other listener doesn't cause update loop? you'd affecting well.

so want both worlds: event fires and listeners decide shouldn't act.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -