Hi Henrik,
I agree that ObservableCollection(Of T) can be used for all tiers.
the exception is not thrown by ObservableCollection(Of T) but by some
action performed by an event handler erroneously invoked by the non-UI
thread in this case?
In my opinion, because the ObservableCollection(Of T) implements the
INotifyCollectionChanged and INotifyPropertyChanged interfaces, it will
cause UI update when the ObservableCollection(Of T) is changed.
Let's say a non-UI thread accesses and changes the ObservableCollection(Of
T), then it is the non-UI thread that performs the UI update in the next
step, which is not allowed in the thread models of both WinForms and WPF
applications.
In WinForms world, the solution is to define a delegate for the method to
access the control, and then call the Invoke or BeginInvoke method of the
WinForms control to invoke the delegate.
In WPF world, the solution is similar but is a little different. We still
need to define a delegate for the method to access the UI element, and then
call the Invoke or BeginInvoke method of the Dispather linked to the UI
thread.
The following is a sample.
delegate void SetTextBoxDelegate();
Dispatcher.Invoke(System.Windows.Threading.Dispatc herPriority.Normal, new
SetTextBoxDelegate(SetTextBox1));
void SetTextBox1()
{
this.textBox1.Text = "some text";
}
For more information on the threading model in WPF, you may visit the
following link:
'Threading Model'
http://msdn2.microsoft.com/en-us/library/ms741870.aspx
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.