1

I've started converting a console based version of a TCP client to GUI. I'll admit, I'm not great with threading and only know a bit of C#. I've managed to get everything working apart from the point when; The client sends another PC (Server) The client's IP so it can then connect back to send data back over, Normally it would reply with the string I set it to: "REPLY INIT", this shows me that I have received data from the other PC. However, when trying to write this to a rich text box / set labels with the data, nothing works; it says its not null but I can't seem to set any GUI elements using the variables in the thread.

 public void Receive()
    {
        try
        {
            byte[] ReceiPacket = new byte[1000];
            Form1.Reciever.Read(ReceiPacket, 0, ReceiPacket.Length);
            Form1.Reciever.Flush();
            string Command = Encoding.ASCII.GetString(ReceiPacket);
            string[] CommandData = System.Text.RegularExpressions.Regex.Split(Command, ">");
                try
                {
                    string LoggingText = CommandData[1].ToString();
                    WriteToLog(LoggingText, "Green");
                }
                catch
                {

                }

        }
        catch
        {
            WriteToLog("Error Receiving!", "Red");
        }


    }

I've removed some code to clean it up a bit, but that's the thread being used to receive stuff.

(The Layout)

The server would reply with something like the following: string>whatever> I used regex to differentiate between the command (string) and the content (whatever).

CharithJ
  • 46,289
  • 20
  • 116
  • 131
Jake B
  • 11
  • 3

1 Answers1

0

SORTED!

I simply placed what I wanted to run inside of that and it works!

                this.Invoke((MethodInvoker)delegate
            {
                WriteToLog("Testing", "Red");
            });
Jake B
  • 11
  • 3