c# - Why is the dispatcher behaving this way when I pass a parameter? -


i'm using datagridview in wpf. in roweditending event, old row (before editing ends) , call method through dispatcher new row (after edit)

private void mygrid_roweditending(object sender, datagridroweditendingeventargs e) {     datarowview oldrowview = e.row.item datarowview;     datarow oldrow = oldrowview.row;     //when put breakpoint before dispatcher called, oldrow has old row values.      dispatcher.begininvoke(new action(() => onrowedit(oldrow, e)), system.windows.threading.dispatcherpriority.background);     //i have passed old row onrowedit }  void onrowedit(datarow oldrow, datagridroweditendingeventargs e) {   //here oldrow has new row values.  } 

the item array of oldrow before call method , array after have called method don't match. reason behind this?

without a good, minimal, complete code example, it's impossible know sure issue in scenario. there's not enough context here.

but likely, you're running temporal issue. is, delegate invoked begininvoke() executed asynchronously, @ indeterminate later time. it's queued execution, it's going executed after update of row occurs, hence see new values time method executed.

possible solutions include:

  1. use invoke() method instead of begininvoke(). executed synchronously, ensuring row object hasn't been modified when onrowedit() method called.
  2. if need values row, extract temporary object (e.g. new array) before calling begininvoke() , pass that object instead of row object itself.
  3. just call onrowedit() directly. lacking complete code example, it's not clear why you're using begininvoke() @ all; typically, user editing actions occur in dispatcher thread, , 1 can access ui objects directly, without need call invoke() or begininvoke(). note practically same option #1…it may using invoke() superfluous.

if none of above options work you, please improve question including code example, explaining why using begininvoke() in first place, , why none of these suggestions work in case.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -