I was trying to troubleshoot an issue that is related to wrong timing. I found two bugs in the following code. Who is up for a challenge finding them?
To make it easy I included the lines that have the bugs
public static bool poll(int param1, int microSeconds)
{
long timeout = DateTime.Now.Ticks + microSeconds*10;
while(true)
{
if (DateTime.Now.Ticks > timeout & microSeconds > 0)
{
return false;
//break;
}
if (DataReady() == true)
return true;
}
}
There a few tools that let you add your own custom rule sets, like FxCop. I’m not entirely sure that you could warn on this exact problem. A unit test would expose this.