GeekByChoiCe 152 Practically a Master Poster

I have created a thread which have to do some xml parsing in its class. The class Inherits from System.Windows.Threading.DispatcherObject
while its parsing i wanna get the dispatcher to add the items to a ObservableCollection(Of T)

i will add my code here and describe the problem in the comments

Private Delegate Sub NewsDelegate(ByVal news As NewsItemClass)

Public Sub ReadAllNews()
		Dim th As New System.Threading.Thread(AddressOf StartReadNews)
		th.IsBackground = True
End Sub

Private Sub StartReadNews()
		Dim xDoc As XDocument = XDocument.Load("myXML.xml")

		For Each newsElement As XElement In xDoc.<news>.<item>
			Dim id As Integer = CInt(newsElement.@id)
			Dim newsItem As New NewsItemClass
			With newsItem
				.ID = CInt(newsElement.@id)
				.Subject = newsElement.<subject>.Value
				.NewsDate = newsElement.<date>.Value
				.Author = newsElement.<author>.Value
				.Content = newsElement.<content>.Value
			End With

			'Dim del As New NewsDelegate(AddressOf AddNews)
			'Catch ex As Exception  'throws: Von diesem CollectionView-Typ werden keine Änderungen der "SourceCollection" unterstützt, wenn diese nicht von einem Dispatcher-Thread aus erfolgen. (whining for a dispatcher)
			'End Try

				If Me.Dispatcher.CheckAccess() Then
				Else 'comes in here
					Me.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Normal, New NewsDelegate(AddressOf AddNews), newsItem)	 'nothing happens
				End If

			Catch ex As Exception 'never thrown
			End Try

		xDoc = Nothing
	End Sub

Friend Sub AddNews(ByVal newsItem As NewsItemClass) 'never get called
		SyncLock Me.News 'tried without synclock but no effect either
		End SyncLock
End Sub

I hope someone can tell me whats wrong on my code plz

ow, one more using .NET 4.0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.