Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

System.UnauthorizedAccessException: Invalid cross-threa... RSS

2 replies

Last post Jul 01, 2008 12:00 PM by hari4u

(0)
  • hari4u

    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

    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

    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