Wednesday 15 January 2014

c# - Why Doesn't the Code Deadlock -


Please explain to me why this code is not the reason of a deadlock?

  Fixed object listlock = new object (); Zero StartSync () {System.Threading.Task..Task.Factory.StartNew ((=) gt; Lock (base) support.opher ("mylistlist");}); } Public Observable Collection & lt; MyObjects & gt; MyList {Lock (Locklock) New Observation Collection & lt; MyObjects & gt; (_ MyOjectjectList); }}   

Some background details:
The program is using the MVVM pattern and MyList is a Datagrid < Strong> WPF UI .
_Office is a random list of objects.

This is because OnPropertyChange notifies the UI only that it will have to obtain new data from MyList and only without asking whether the UI actually receives data or No?
I know that OnPropertyChanged is said to be on a separate thread but the UI is present on a thread (the oo is not there) then the thread which is notified is also the thread that receives the data I think lock Will not be able to continue because of this?

The key is that the code of changing property handler some code schedule Does access MyList on the UI thread, but it does not wait for to end it

Then, a possible sequence of events It is:

  1. StartAsync () locks on a background thread. > is for .
  2. PropertyChanged handler for codecs code MyList on the UI thread
  3. By changing property handler for returns.
  4. The lock is in progress.
  5. Use the UI thread attempt MyList .
  6. The UI threads lock without waiting, because no other thread is its owner.
  7. One ?? |

    Another way to put it: I hope you expect it to be handler for PropertyChanged : < Pre> Dispatcher.Invoke (() => {If (e.PropertyName == "Mylist") {var newList = model.MyList; // Set new list as current value of some compulsion} });

    But in fact, this is something like this (the only difference is the first line):

      Dispatcher.BeginInvoke ((=) => {if ( E.PropertyName == "Mylist") {var newList = Model. MyList; // set as the current value of some bonds newList}});    

No comments:

Post a Comment