Click here to Skip to main content
15,887,776 members
Home / Discussions / C#
   

C#

 
QuestionThread Freeze when trying Abort Pin
Member 1098515215-Aug-14 12:17
Member 1098515215-Aug-14 12:17 
Hi all
why does this form freeze when I press the strtChatBtn at the second time?

Server Form Class
C#
public partial class Server_Design : Form
{
    Thread serverStart;

    private bool btnStartStop = true;

    public Server_Design()
    {
        InitializeComponent();
    }

    private void Server_Design_Load_1(object sender, EventArgs e)
    {

    }

    private void strtChatBtn_Click(object sender, EventArgs e)
    {

            if (btnStartStop)
            {
                    serverStart = new Thread(new         ThreadStart(Connection.StartListen));
                    serverStart.Start();
                    strtChatBtn.Text = "Stop Chat";
                    btnStartStop = false;
            }
            else
            {
                this.serverStart.Abort();
                Connection.StopListen();
                strtChatBtn.Text = "Start Chat";
                btnStartStop = true;
            }

    }
    }
}


Connection Class
C#
   public static class Connection
    {
        static IPAddress srvIP = IPAddress.Parse("127.0.0.1");
        static int srvPort = 8888;

        static TcpListener server = new TcpListener(srvIP, srvPort);

        public static void StartListen()
        {     
            server.Start();

            while (1 != 0)
            {

                TcpClient client = server.AcceptTcpClient();

                NetworkStream ns = client.GetStream();
                StreamWriter sw = new StreamWriter(ns);
                StreamReader sr = new StreamReader(ns);

                ns = client.GetStream();

                client.Close();
                ns.Close();
                sw.Close();
                sr.Close();

            }
        }

       public static void StopListen()
        {
            server.Stop();
        }
    }
}

GeneralRe: Thread Freeze when trying Abort Pin
PIEBALDconsult15-Aug-14 12:47
mvePIEBALDconsult15-Aug-14 12:47 
QuestionSummary Report in GridView Pin
sk_ko14-Aug-14 22:02
sk_ko14-Aug-14 22:02 
AnswerRe: Summary Report in GridView Pin
Chris Quinn14-Aug-14 22:36
Chris Quinn14-Aug-14 22:36 
AnswerRe: Summary Report in GridView Pin
Mycroft Holmes14-Aug-14 23:00
professionalMycroft Holmes14-Aug-14 23:00 
GeneralScope of Share point and Silverlight Pin
Member 1059394814-Aug-14 3:40
Member 1059394814-Aug-14 3:40 
GeneralRe: Scope of Share point and Silverlight Pin
Richard MacCutchan14-Aug-14 4:22
mveRichard MacCutchan14-Aug-14 4:22 
Questionhow do i make each combo box to show a dropdown of the value of the Quantity it has fetched. Pin
Member 1050484913-Aug-14 9:02
Member 1050484913-Aug-14 9:02 
SuggestionRe: how do i make each combo box to show a dropdown of the value of the Quantity it has fetched. Pin
ZurdoDev13-Aug-14 9:24
professionalZurdoDev13-Aug-14 9:24 
QuestionHow to increment div count in path Pin
Member 1098388513-Aug-14 6:09
Member 1098388513-Aug-14 6:09 
Questionc# Play Video Fullscreen Pin
Member 416962813-Aug-14 5:20
Member 416962813-Aug-14 5:20 
AnswerRe: c# Play Video Fullscreen Pin
Simon_Whale13-Aug-14 5:41
Simon_Whale13-Aug-14 5:41 
GeneralRe: c# Play Video Fullscreen Pin
Member 416962813-Aug-14 5:53
Member 416962813-Aug-14 5:53 
GeneralRe: c# Play Video Fullscreen Pin
Dave Kreskowiak13-Aug-14 6:05
mveDave Kreskowiak13-Aug-14 6:05 
GeneralRe: c# Play Video Fullscreen Pin
Member 416962813-Aug-14 8:42
Member 416962813-Aug-14 8:42 
GeneralRe: c# Play Video Fullscreen Pin
Dave Kreskowiak13-Aug-14 12:27
mveDave Kreskowiak13-Aug-14 12:27 
GeneralRe: c# Play Video Fullscreen Pin
Bernhard Hiller13-Aug-14 21:48
Bernhard Hiller13-Aug-14 21:48 
Question[CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Member 1062093513-Aug-14 4:17
Member 1062093513-Aug-14 4:17 
SuggestionRe: [CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Richard Deeming13-Aug-14 4:57
mveRichard Deeming13-Aug-14 4:57 
GeneralRe: [CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Member 1062093513-Aug-14 20:02
Member 1062093513-Aug-14 20:02 
QuestionRegarding the usage of generic in real life Pin
Tridip Bhattacharjee12-Aug-14 21:20
professionalTridip Bhattacharjee12-Aug-14 21:20 
AnswerRe: Regarding the usage of generic in real life Pin
Manfred Rudolf Bihy12-Aug-14 21:51
professionalManfred Rudolf Bihy12-Aug-14 21:51 
GeneralRe: Regarding the usage of generic in real life Pin
Tridip Bhattacharjee12-Aug-14 23:18
professionalTridip Bhattacharjee12-Aug-14 23:18 
GeneralRe: Regarding the usage of generic in real life Pin
Debabrata TPX12-Aug-14 23:49
Debabrata TPX12-Aug-14 23:49 
GeneralRe: Regarding the usage of generic in real life Pin
Tridip Bhattacharjee13-Aug-14 21:25
professionalTridip Bhattacharjee13-Aug-14 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.