Sign In|Join
Home/Silverlight.NET Forums/General Silverlight Programming/Programming with .NET - General/System.UnauthorizedAccessException: Invalid cross-thread access error
Last post Jul 01, 2008 12:00 PM by hari4u
Member
58 Points
95 Posts
Jul 01, 2008 11:29 AM | LINK
hello,
I'm getting this error when I'm trying to bind data dynamically from a textbox control to a method,
here is the code...
private void btn1_Click(object sender, RoutedEventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://postbox.instasecure.com/service/soap/")); request.Method = "POST"; request.ContentType = "application/json"; request.BeginGetRequestStream(new AsyncCallback(createtagRequestHandler), request); }
void createtagRequestHandler(IAsyncResult asyncResult) { HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState; //getting that error near s... string s = createTagXML(txtname.Text.Trim(),txtcolor.Text.Trim()); StreamWriter postdatawriter = new StreamWriter(request.EndGetRequestStream(asyncResult)); postdatawriter.Write(s, 0, s.Length); postdatawriter.Flush(); postdatawriter.Close(); request.BeginGetResponse(new AsyncCallback(createtagResponseHandler), request); }
thanx in advance,
Hari
160 Points
159 Posts
Jul 01, 2008 11:47 AM | LINK
Hi Hari,
R u getting this error in beta 2?
If yes, then put the content in this block.
this.Dispatcher.BeginInvoke(delegate() {
//content
});
in your code...
void createtagRequestHandler(IAsyncResult asyncResult) {
this.Dispatcher.BeginInvoke(delegate() { HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState; //getting that error near s... string s = createTagXML(txtname.Text.Trim(),txtcolor.Text.Trim()); StreamWriter postdatawriter = new StreamWriter(request.EndGetRequestStream(asyncResult)); postdatawriter.Write(s, 0, s.Length); postdatawriter.Flush(); postdatawriter.Close(); request.BeginGetResponse(new AsyncCallback(createtagResponseHandler), request);
}); }
regards,
rams.
Jul 01, 2008 12:00 PM | LINK
thanx a lot
that solved my problem..
hari
hari4u
Member
58 Points
95 Posts
System.UnauthorizedAccessException: Invalid cross-thread access error
Jul 01, 2008 11:29 AM | LINK
hello,
I'm getting this error when I'm trying to bind data dynamically from a textbox control to a method,
here is the code...
private void btn1_Click(object sender, RoutedEventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://postbox.instasecure.com/service/soap/"));
request.Method = "POST";
request.ContentType = "application/json";
request.BeginGetRequestStream(new AsyncCallback(createtagRequestHandler), request);
}
void createtagRequestHandler(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
//getting that error near s...
string s = createTagXML(txtname.Text.Trim(),txtcolor.Text.Trim());
StreamWriter postdatawriter = new StreamWriter(request.EndGetRequestStream(asyncResult));
postdatawriter.Write(s, 0, s.Length);
postdatawriter.Flush();
postdatawriter.Close();
request.BeginGetResponse(new AsyncCallback(createtagResponseHandler), request);
}
thanx in advance,
Hari
RamsZone
Member
160 Points
159 Posts
Re: System.UnauthorizedAccessException: Invalid cross-thread access error
Jul 01, 2008 11:47 AM | LINK
Hi Hari,
R u getting this error in beta 2?
If yes, then put the content in this block.
this.Dispatcher.BeginInvoke(delegate()
{
//content
});
in your code...
void createtagRequestHandler(IAsyncResult asyncResult)
{
this.Dispatcher.BeginInvoke(delegate()
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
//getting that error near s...
string s = createTagXML(txtname.Text.Trim(),txtcolor.Text.Trim());
StreamWriter postdatawriter = new StreamWriter(request.EndGetRequestStream(asyncResult));
postdatawriter.Write(s, 0, s.Length);
postdatawriter.Flush();
postdatawriter.Close();
request.BeginGetResponse(new AsyncCallback(createtagResponseHandler), request);
});
}
regards,
rams.
hari4u
Member
58 Points
95 Posts
Re: Re: System.UnauthorizedAccessException: Invalid cross-thread access error
Jul 01, 2008 12:00 PM | LINK
thanx a lot
that solved my problem..
hari