Results 1 to 4 of 4

Thread: [RESOLVED] C# Unable to Show Socket Data In textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Resolved [RESOLVED] C# Unable to Show Socket Data In textbox

    I am having problem to show the Data arrived from System.Net.Sockets onto textbox

    'Cross-thread operation not valid: Control 'txtDataRx' accessed from a thread other than the thread it was created on'

    Code:
    public void ReceiveSckData(IAsyncResult aData)
            {
                try
                {
                    CSocketPacket theSockId = (CSocketPacket)aData.AsyncState;
                    //end receive...
                    int iRx = 0;
                    iRx = theSockId.thisSocket.EndReceive(aData);
                    char[] chars = new char[iRx + 1];
                    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                    int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
                    System.String szData = new System.String(chars);
                    //MessageBox.Show(theSockId.dataBuffer.Length.ToString());
                    MessageBox.Show(szData);
                    txtDataRx.Text = szData; // I AM GETTING ERROR HERE
    
                    
                    
                    
                }
                catch (ObjectDisposedException)
                {
                    System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
                }
                catch (SocketException se)
                {
                    MessageBox.Show(se.Message);
                }
            }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: C# Unable to Show Socket Data In textbox

    This is the VB.NET forum. C# questions belong in the C# forum. If you feel that your question is not language-specific then post in the .NET Architecture & Design forum. The only reason that C# code should be being posted in the VB.NET forum is if you are having trouble converting it to VB.NET.

    With regards to the question, follow the CodeBank link in my signature and check out my post on Access Controls From Worker Threads. The SerialPort class raises its events asynchronously, i.e. on thread pool threads.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: C# Unable to Show Socket Data In textbox

    You originally posted this question in the VB.NET forum. I answered it there 2 hours and 36 minutes before you posted it here. You first posted a C# question in the VB.NET forum, then you ignored an answer when it was provided, then you posted the same question a second time. Please post each question once and once only, in the most appropriate forum for the topic. If you post in the wrong forum then don't double post; ask the mods to move the thread.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: C# Unable to Show Socket Data In textbox

    Duplicate threads merged, and identical post removed - please post each question (or variation of it) only once. If you think you have posted in the wrong forum, PM a moderator to ask them to move it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width