thread.sleep的问题,帮下忙了,各位高手

lovelingfe 2010-10-03 07:54:58
在代码里使用Thread.Sleep(200);后,有时候程序能运行成功,有时候会在中间突然卡掉。去掉这段代码就好了。
代码是VS2008转成2005的。谢谢各位了。
...全文
96 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovelingfe 2010-10-03
  • 打赏
  • 举报
回复
/ do a dfs of maze and display as you go
public void dfs(int i, int j)
{
StackNode p=new StackNode();
theStack = new StackNode();
theStack.xcoord = i;
theStack.ycoord = j;
theStack.next = null;
// set current square to visited
theMaze.mazegrid[i,j] = 3;

while (empty())
{
p = pop();
if (theMaze.mazegrid[p.xcoord + 1,p.ycoord] == 0)
{
theMaze.mazegrid[p.xcoord + 1, p.ycoord] = 3;
visit(p.xcoord + 1, p.ycoord);
}
if (theMaze.mazegrid[p.xcoord,p.ycoord+1] == 0)
{
theMaze.mazegrid[p.xcoord, p.ycoord + 1] = 3;
visit(p.xcoord, p.ycoord+1);
}
if (theMaze.mazegrid[p.xcoord - 1,p.ycoord] == 0)
{
theMaze.mazegrid[p.xcoord - 1, p.ycoord] = 3;
visit(p.xcoord - 1, p.ycoord);
}
if (theMaze.mazegrid[p.xcoord,p.ycoord-1] == 0)
{
theMaze.mazegrid[p.xcoord, p.ycoord - 1] = 3;
visit(p.xcoord, p.ycoord-1);
}
//display the maze
theMaze.display_maze(offScreenDC);
drawArea.DrawImage(offScreenBmp, 0, 0);
//wait a bit
Thread.Sleep(200);
}

// move the bot and return to original position
// after all children have been searched

// set current square to revisited (i.e. backtracked to)
theMaze.mazegrid[i,j] = 4;
//display the maze
theMaze.display_maze(offScreenDC);
drawArea.DrawImage(offScreenBmp, 0, 0);
//wait a bit
}

thread.sleep是在重复用的,并且不能删掉,这是作业
wuyq11 2010-10-03
  • 打赏
  • 举报
回复
其他代码
ZengHD 2010-10-03
  • 打赏
  • 举报
回复
那就去掉吧

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧