2014-08-29 5 views
2

변수를 보았을 때 My PropertyChanged 이벤트가 올바르게 설정되지만 코드의 어딘가에서 null로 재설정되고 어떻게되는지 파악할 방법이 없습니다. 하여 PropertyChanged에 null로 설정지고 WHERE 식별을 시도PropertyChangedEventHandler가 변경 될 때 감지

public event PropertyChangedEventHandler PropertyChanged; 

    //this is in the NotifyTaskCompletion class, as used from the blog 
// http://msdn.microsoft.com/en-us/magazine/dn605875.aspx 
    private async Task WatchTaskAsync(Task task) 
    { 
     try 
     { 
      await task; //After this task, PropertyChanged gets set to a non-null method("Void OnPropertyChanged()") 
     } 
     catch 
     { 
     } 
     //PropertyChanged, which was set to a value after the task was run, and still not null during IdentifyCompleted getting set, is now null here 
     var propertyChanged = PropertyChanged; 
     if (propertyChanged == null) 
      return; 
     //other code 
} 


    //My Watch variable of PropertyChanged is still good after this setter is run. 
    public NotifyTaskCompletion<GraphicCollection> IdentifyCompleted 
    { 
     get { return _IdentifyCompleted; } 
     set 
     { 
      _IdentifyCompleted = value; 
     // _IdentifyCompleted.PropertyChanged+= new PropertyChangedEventHandler(this, new  PropertyChangedEventArgs("IdentifyCompleted")); 
      // NotifyPropertyChanged(); 
     } 
    } 

내 주요 문제는 내가 {; 얻을 세트}을 사용할 수 없다는 것입니다 : 여기

코드를 제공한다. 그래서 내 주된 질문은, 누군가 분명히 틀린 것을 보지 않는다면, 그것이 null로 설정되는 곳을 찾는 방법은 무엇입니까? 도움을 주셔서 감사합니다.

private PropertyChangedEventHandler _propertyChanged; 
    public event PropertyChangedEventHandler PropertyChanged 
    { 
     add { _propertyChanged += value; } 
     remove { _propertyChanged -= value; } 
    } 

을 그리고 여기에 문제가 다음과 같이

편집 마지막 포스터의 제안으로 당

, 내 코드를 설정합니다.

//this is in my View Model. The ViewModel CONTAINS NotifyTaskCompletion<GraphicCollection> IdentifyCompleted which in turn implements INotifyPropertyChanged and has its own PropertyChanged that is not getting set 

    private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") 
    { 
     if (PropertyChanged != null) 
     { 
//This line sets the PopertyChanged in the view model AND in the NotifyTaskCompletion class somehow, but I don't know how it is setting it properly in the NotifyTaskCompletion class in my other project where this code works, When I step through this line in my code, it doesn't trigger 
//the add{} of the PropertyChanged in NotifyTaskCompletion, but it DOES in my other project... 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 

그럼 이제는 어떤 줄이 작동하는지 알아볼 수는 있지만 작동하지 않는 이유는 알 수 없습니다. 다른 아이디어? 지금까지 도움을 주셔서 감사합니다.

+0

은 WatchTaskAsync 메소드의 호출 코드를 보여줍니다. – pushpraj

+0

http://msdn.microsoft.com/en-us/magazine/dn605875.aspx 나는 정확한 코드를 사용하고 있으며 일을 수행하는 방식을 모방하려고했습니다. 하나의 프로젝트에서 작동하지만 다른 프로젝트에서는 작동하지 않습니다. –

+0

비동기 바인딩을 만들려고하는 것 같습니다. 이 경우 http://stackoverflow.com/questions/24731335/async-loading-images-in-wpf-value-converter/24731602#24731602가 도움을 줄 수 있는지 확인하십시오. – pushpraj

답변

7

당신은 당신의 자신의 이벤트 접근을 쓸 수 있습니다 : 당신은 다음 중단 점을 설정할 수 있습니다

private PropertyChangedEventHandler propertyChanged; 
public event PropertyChangedEventHandler PropertyChanged { 
    add { propertyChanged += value; } 
    remove { propertyChanged -= value; } 
} 

. 이것은 스레드로부터 안전하지 않습니다.

+0

스레드 안전성을 위해'Delegate.Combine'과'Delegate.Remove'를 사용해야합니다. – Zer0

+0

@ Zer0 : 틀린; '+ ='와'- ='는 그 메소드를 컴파일하고, 둘 다 경쟁 조건에 동등하게 취약하다. – SLaks

+0

와우. 내가 말하고자하는 것은 이벤트에서'+ ='또는'- ='을 할 때 .NET과 같이'Delegate.Combine'과'Delegate.Remove'와'Interlocked.CompareExchange'를 사용해야한다는 것입니다. 그렇게하면 경쟁 조건을 도입하지 않고도 디버깅에 사용할 수 있습니다. – Zer0

관련 문제