WPF label problem

02/23/2017 22:08 Underfisk#1
Hi, if got recently being trying WPF and my problem is update an label (i know how to do but i think it's something wrong).
Here is an sample of code, and i cant understand why it's not changing after TCP result.

Code:
public void check()
{
MainMenu x = new MainMenu();
            //PING -> WORLD Server
            if (_tcpREC(Convert.ToInt32(Properties.Settings.Default["worldport"].ToString())) == true)
            {
                x.dksv.Content = "Online";
                x.dksv.Foreground = Brushes.Green;
            }
            else
            {
                x.dksv.Content = "Offline";
                x.dksv.Foreground = Brushes.Red;
            }
}
public Boolean _tcpREC(int port)
        {
            IniFile configFile = new IniFile();
            //Check if is open or not on the server ip 
            using (TcpClient rec = new TcpClient())
            {
                try
                {
                    rec.Connect(configFile.Read("Server Name", "MSSQL"), port);
                    if (rec.Connected == true)
                    {
                        return true;
                    }

                }
                catch
                {
                    return false;
                }
            
            }
And basicly i dont get label's updated.
x = my new other form
02/24/2017 11:48 Ludder231#2
do you have multiple forms? are you working with multiple threads? i guess you need to invoke your label.
02/24/2017 12:11 XYZ-Cannon#3
First of all you don't need to check a boolean in your if-statement (your == true is useless).
You are creating a new Main Menu everytime you check? Use better method names and split your method. By checking something you should never create a new interface.
02/24/2017 20:26 schnewin#4
Why you don't use Databinding with WPF ([Only registered and activated users can see links. Click Here To Register...])?
02/24/2017 21:09 Underfisk#5
Btw im new at wpf, and i remmeber from Java to test the object and variables as static , and they work well now but i still can't understand well what's the best way to invoke the forms. And yes, i'm using multiple

Quote:
Originally Posted by XYZ-Cannon View Post
First of all you don't need to check a boolean in your if-statement (your == true is useless).
You are creating a new Main Menu everytime you check? Use better method names and split your method. By checking something you should never create a new interface.
Thx, and iam looking for a way to test multiple socket tests like i do in this way, but i think its not the best way to test the port. If you could recommend something i'll try ofc.
02/27/2017 11:09 XYZ-Cannon#6
Quote:
Originally Posted by Underfisk View Post
Btw im new at wpf, and i remmeber from Java to test the object and variables as static , and they work well now but i still can't understand well what's the best way to invoke the forms. And yes, i'm using multiple



Thx, and iam looking for a way to test multiple socket tests like i do in this way, but i think its not the best way to test the port. If you could recommend something i'll try ofc.
How about testing a port with a method and implement a parameter like the number of the port you want to test? F.e.:

checkPort(int portnumber){}
02/27/2017 12:48 Underfisk#7
Im doing it right now, i get the port but i need to make a "big" if statement for check if is online or not. basicly i'm trying to find a way to send multiple ports but i think gotta try send a full array with the ports numbers and return