2

I wrote a C#, WPF, .NET 4.0 application. A textblock in the view is bind directly to a string property on the model which is updated from a background thread, when the property value is changed, a PropertyChanged event is raise from the model.

If i'm running the program on win7 i can see that the view is updated with the correct value when ever the property is updated. On windows8 however, i can see that the event is raise, but the view does not get updated.

I read here that binding scalar properties marshal automatically for ui thread. and i can see in win7 that it does work this way.

any ideas what can be the reason that this problem exists on windows 8? the program is targeted for .net 4.0, but windows 8 comes with .net 4.5 installed.

how can i further debug this issue?

I prefer not to change all my property change notifications to specifically raise from the dispatcher thread if i don't have to. i wish to understand the problem first.

Thanks

Community
  • 1
  • 1
avivr
  • 2,573
  • 3
  • 22
  • 34
  • 1
    `PropertyChanged` should not be fired in a Background thread. Use `Dispatcher.BeginInvoke()` or something. – Federico Berasategui Jul 23 '13 at 14:32
  • You shouldn't update UI in `Background Thread` – Sriram Sakthivel Jul 23 '13 at 14:33
  • @HighCore please read my whole question first. i refer to this issue. – avivr Jul 23 '13 at 14:34
  • @avivr **PropertyChanged should not be fired in a Background thread. Use `Dispatcher.BeginInvoke()` or something**. I already read your question. My point still stands. – Federico Berasategui Jul 23 '13 at 14:35
  • my question is about the diff behavior between win7/win8. how come when updating the property from background thread in win7 the view gets updated? – avivr Jul 23 '13 at 14:39
  • [Read through this analogy for pointers from Eric Lippert](http://stackoverflow.com/a/6445794/1834662). Just because something worked does not guarantee a valid result especially when it's known to be undefined behavior. ye it prolly worked in Windows-7, and with the entire rewrite of the OS in Windows-8 they probably switched something somewhere that ends up affecting this. Is it really that important to know the specifics here when ppl have told you it's always been wrong. its wrong coding practice in either OS version. – Viv Jul 23 '13 at 16:06
  • is there some official microsoft documentation saying that you should fire the event from UI thread? – avivr Jul 23 '13 at 19:16
  • Why not just take the good advice of people that are offering to help you in their own time? If you still don't believe that you **should not update the UI from a background thread**, just take a look online at the wealth of information on the subject. This is not a Microsoft issue, it is an industry best practice issue. – Sheridan Jul 24 '13 at 12:23
  • 1
    i'm not against taking good advice, it's just that i see different information about this issue on the web, like [here](http://stackoverflow.com/questions/1321423/does-wpf-databinding-marshall-changes-to-the-ui-thread) and [here](http://stackoverflow.com/questions/6773908/wpf-are-notifypropertychangeds-marshalled-to-the-dispatcher), and making the change mean two things - 1. if we're using INPC for notifying updates not related to ui, the ui thread is going to be loaded anyway. and 2. we need to invest lots of work in order to change it, both in rewriting and in testing. – avivr Jul 24 '13 at 14:09

0 Answers0