I have found a few examples online of how to write a socket server for a chat application. I pieced a few together and got it working great in a console application. I have since tried pushing it to a Winforms application and run into a small snag.
When I F5 my app (or build and launch the exe), the form disappears when I instantiate my ChatServer class. The server does indeed run (I can connect to it with clients and chat 'till the cows come home), but I want the form to remain visible as it has a large textbox I'm using to write events to.
my form1.cs file is nothing more than this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsChat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
txtConsole.Text = "Starting Chat\r\n";
StartChat();
}
private void StartChat()
{
ChatServer server = new ChatServer(this);
}
}
}
There is nothing in my ChatServer class that is telling my form1 object to hide the form...any idea what would cause the form to disappear? If I comment out ChatServer server = new ChatServer(this); the form shows up with my large text box (but obviously the chat server doesn't start).