jamie_pattison
Well-known member
- Joined
- Sep 9, 2008
- Messages
- 116
- Programming Experience
- Beginner
I have an application that i cant figure why im receiving the error:
System.UnauthorizedAccessException was unhandled
Message=Invalid cross-thread access.
It seems the error kicks in when i try to load the items in the textbox, although if the code to load the items is elsewhere i receive a NullException. Any reason why this could be happening or what i could be doing wrong? I can access the feed with other applications?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim request As HttpWebRequest = HttpWebRequest.Create("http://someInformation.xml")
request.BeginGetResponse(New AsyncCallback(AddressOf ResponseHandler), request)
End Sub
Private Sub ResponseHandler(ByVal AsyncResult As IAsyncResult)
Dim webReq As HttpWebRequest = DirectCast((AsyncResult.AsyncState), HttpWebRequest)
Dim webRes As HttpWebResponse = DirectCast(webReq.EndGetResponse(AsyncResult), HttpWebResponse)
If webRes.StatusCode = HttpStatusCode.OK Then
Dim xr As XmlReader = XmlReader.Create(webRes.GetResponseStream)
m_NewFeed = SyndicationFeed.Load(xr)
End If
webRes.Close()
TextBox1.Text = m_NewFeed.Items(1).Title.ToString
End Sub
Thanks
System.UnauthorizedAccessException was unhandled
Message=Invalid cross-thread access.
It seems the error kicks in when i try to load the items in the textbox, although if the code to load the items is elsewhere i receive a NullException. Any reason why this could be happening or what i could be doing wrong? I can access the feed with other applications?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim request As HttpWebRequest = HttpWebRequest.Create("http://someInformation.xml")
request.BeginGetResponse(New AsyncCallback(AddressOf ResponseHandler), request)
End Sub
Private Sub ResponseHandler(ByVal AsyncResult As IAsyncResult)
Dim webReq As HttpWebRequest = DirectCast((AsyncResult.AsyncState), HttpWebRequest)
Dim webRes As HttpWebResponse = DirectCast(webReq.EndGetResponse(AsyncResult), HttpWebResponse)
If webRes.StatusCode = HttpStatusCode.OK Then
Dim xr As XmlReader = XmlReader.Create(webRes.GetResponseStream)
m_NewFeed = SyndicationFeed.Load(xr)
End If
webRes.Close()
TextBox1.Text = m_NewFeed.Items(1).Title.ToString
End Sub
Thanks