None of the buttons is working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pantelimon Fl
    New Member
    • Dec 2011
    • 1

    #1

    None of the buttons is working

    When i start the program, it simply freezes. I mean if i push any button, it doesn't work. Only button10 is working which is closing the form.
    What is the problem here?

    using System;
    using System.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    //using System.Linq;
    using System.Text;
    using System.Windows. Forms;
    using System.Diagnost ics;
    using System.IO;
    using System.Threadin g;


    namespace Samp_cpanel
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }
    Process p = new Process();
    new bool running = false;
    new bool loaded = false;

    private void button1_Click(o bject sender, EventArgs e)
    {
    if (running == true)
    {
    MessageBox.Show ("Server already running!", "Error!");
    }
    else
    {
    p.StartInfo.Fil eName = "samp-server.exe";
    p.Start();
    running = true;
    Thread.Sleep(20 0);
    Query.Query sQuery = new Query.Query("76 .10.223.139", 7777);
    sQuery.Send('i' );

    int count = sQuery.Recieve( );

    string[] info = sQuery.Store(co unt);
    if (info.Length == 0)
    {
    hostname.Text = "The server is DOWN!";
    }
    else
    {
    Query.Query dQuery = new Query.Query("76 .10.223.139", 7777);
    dQuery.Send('c' );

    int c2 = dQuery.Recieve( );
    string[] pl = dQuery.Store(c2 );
    for (int i = 0; i < Convert.ToInt64 (info[1])*2; i++)
    {
    ListViewItem lvi = new ListViewItem(pl[i]);
    lvi.SubItems.Ad d(pl[i + 1]);
    listView1.Items .Add(lvi);
    i++;
    }

    hostname.Text = info[3];
    players.Text = info[1] + " / " + info[2];
    mapname.Text = info[5];
    gmtext.Text = info[4];
    }
    }
    }

    private void button2_Click(o bject sender, EventArgs e)
    {
    try
    {
    p.Kill();
    running = false;
    }
    catch { }
    }

    private void Form1_Load(obje ct sender, EventArgs e)
    {
    }

    private void button3_Click(o bject sender, EventArgs e)
    {
    try
    {
    p.Kill();
    p.Start();
    }
    catch { }
    }

    private void button5_Click(o bject sender, EventArgs e)
    {
    textBox1.Text = File.ReadAllTex t("server.cfg") ;
    loaded = true;
    }

    private void button4_Click(o bject sender, EventArgs e)
    {
    if (loaded == false)
    {
    MessageBox.Show ("You must load the cfg file", "Error!");
    }
    else
    {
    File.WriteAllTe xt("server.cfg" , textBox1.Text);
    MessageBox.Show ("The cfg file was totally edited", "Success!") ;
    }
    }
    private void button6_Click(o bject sender, EventArgs e)
    {
    Query.RCONQuery jQuery = new Query.RCONQuery (textBox5.Text, Convert.ToInt16 (textBox6.Text) , textBox7.Text);
    if (textBox2.Text == "")
    {
    if (textBox3.Text == "")
    {
    if (textBox4.Text == "")
    {
    }
    else
    {
    jQuery.Send("ma pname " + textBox4.Text);
    }
    }
    else
    {
    jQuery.Send("ga memodetext " + textBox3.Text);
    }
    }
    else
    {
    jQuery.Send("ho stname " + textBox2.Text);
    }

    }

    private void textBox6_TextCh anged(object sender, EventArgs e)
    {

    }

    private void button7_Click(o bject sender, EventArgs e)
    {
    Query.Query cQuery = new Query.Query("12 7.0.0.1", 7777);
    cQuery.Send('i' );

    int count = cQuery.Recieve( );

    string[] info = cQuery.Store(co unt);
    if (info.Length == 0)
    {
    hostname.Text = "Serverul este DOWN!";
    players.Text = "";
    mapname.Text = "";
    gmtext.Text = "";
    }
    else
    {
    hostname.Text = info[3];
    players.Text = info[1] + " / " + info[2];
    mapname.Text = info[5];
    gmtext.Text = info[4];
    }
    }


    private void button10_Click( object sender, EventArgs e)
    {
    this.Close();
    }

    private void groupBox1_Enter (object sender, EventArgs e)
    {
    }


    }
    }
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    If nothing happens when you push the buttons, two things are possible...

    1) The event handlers didn't connect. An easy check is to put a message box call as the first line in an event handler, or a Console.WriteLi ne message, and see if that happens. Alternatively you could set a breakpoint. If the event handler isn't being called, ensure it's actually attached to the event. If you did it through the designer this would be in the _____.designer. cs file for your form.

    2) If you do the above and your event is working, then it's likely your code doesn't work properly. I took a quick look and this looks like it's your own stuff so I can't really help you very much. Debug it using breakpoints and output statements and try to figure out what's not working.

    Comment

    • arie
      New Member
      • Sep 2011
      • 64

      #3
      I think it is probable that your comunication with the server causes this. Does the methods you use (Send/Receive) are blocking or unblocking? If it's the former, then the situation you described can happen (I mean, the GUI will freeze until the response is received). To avoid it, you can e.g. use BackroundWorker .

      Comment

      Working...