I'm working on a port scanner that constantly displays the status of a game server, but for some reason I keep getting this error : http://i47.tinypic.com/vpgkl4.png
I'm pretty new to the c sharp language, and I've been looking around online about delegates, but I seem to have messed up somewhere after following an example.
Everything works fine until I decide to terminate my program, that's when the error comes up, and visual studio does not stop debugging and unlocking the source files automatically.(i have to hit ctrl+f5 manually). I'd be grateful if someone would point out my error(s).
C#
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespaceAfterPatch_SC__Launcher
{
publicpartialclassfrm_StatusChecker : Form
{
Thread WorldServerStatusThread;
publicfrm_StatusChecker()
{
InitializeComponent();
}
privatevoidfrm_StatusChecker_Load(object sender, EventArgs e)
{
this.WorldServerStatusThread = new Thread(new ThreadStart(this.WorldServerStatus));
this.WorldServerStatusThread.Start();
}
delegatevoidSetTextCallback(string Text);
privatevoidWorldServerStatus()
{
while ( true )
{
try
{
Thread.Sleep(1000);
TcpClient CheckWorldServer = new TcpClient();
CheckWorldServer.Connect("63.251.217.4", 8484);
if (this.label_WorldServerStatus.InvokeRequired)
{
SetTextCallback A1 = new SetTextCallback(SetText);
this.Invoke(A1, newobject[] { "ONLINE" });
}
else
{
this.label_WorldServerStatus.Text = "ONLINE";
}
}
catch
{
if (this.label_WorldServerStatus.InvokeRequired)
{
SetTextCallback A2 = new SetTextCallback(SetText1);
this.Invoke(A2, newobject[] { "OFFLINE" });
}
else
{
this.label_WorldServerStatus.Text = "OFFLINE";
}
}
}
}
privatevoidSetText(string StatusOnline)
{
this.label_WorldServerStatus.Text = "ONLINE";
}
privatevoidSetText1(string StatusOffline)
{
this.label_WorldServerStatus.Text = "OFFLINE";
}
}
}
I apologize beforehand for how messy or nooby my coding may be..
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Sam HobbsRank #107 · 20.5K reputationPosted Dec 23, 2009, 6:05 AM EST
0
Don't use Ctrl-F5 to stop the program since Ctrl-F5 is for starting the program. The program does not stop because you are continually starting it.
Thanks for the tip, but I ended up finding the problem within the while ( true ) loop. I used a boolean and it solved my problem.
0
Sam HobbsRank #107 · 20.5K reputationPosted Dec 24, 2009, 9:48 PM EST
0
In the future, be as accurate as you can in your request for assistance from others. The accuracy of your question can determine the usefulness of responses.
Sam HobbsRank #107 · 20.5K reputationPosted Dec 23, 2009, 6:05 AM EST
jon2 reputationPosted Dec 23, 2009, 6:33 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 24, 2009, 9:48 PM EST