Sunday, 25 August 2013

Using Threads, Is this a good way?

Using Threads, Is this a good way?

So, i have 2 threads, one listen on TCP, other Render in a loop. So, to
Start and End, i have this code:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
try
{
if (ReceiveCheck.Checked)
{
tcplisten.Start();
ListenThread = new Thread(new ThreadStart(Listen));
ListenThread.Start();
RenderThread = new Thread(new ThreadStart(Render));
RenderThread.Start();
}
else
{
tcplisten.Stop();
RenderThread.Abort();
ListenThread.Abort();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Checkbox");
}
}
Is this a good way to handle the Threads? To just start then, and kill
them when i want to?

No comments:

Post a Comment