المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Better way to achive this ?



C# Programming
06-24-2009, 08:32 PM
Hi im new to c# and im building a program to telnet my server. Im trying to prevent the situation below

HostName> A command that will take a long time
The next command HostName>

Where the application sends the next command before the server has completed the last one .

Here is my code

public void Run(string cmd)
{
System.Threading.Thread.Sleep(300);
string lastCharacter = Status.Substring(Status.Length - 2, 1);
if (lastCharacter == ">")
{
WriteLine(cmd + "\n");
}
else
{
Run(cmd);
}
}

I want to get rid of the System.Threading.Thread.Sleep(); functions because they are a major source of exceptions in the program . Is there anyway to solve this problem without System.Threading.Thread.Sleep() and withut sucking up all the CPU time ?