小编Ult*_*loy的帖子

没有睡觉等待?

我正在尝试做的是启动一个函数,然后将bool更改为false,等待一秒钟再次将其变为true.但是我想在没有等待功能的情况下这样做,我该怎么做?

我只能使用Visual C#2010 Express.

这是有问题的代码.我正在尝试接收用户输入(例如右箭头)并相应地移动,但在角色移动时不允许进一步输入.

        x = Test.Location.X;
        y = Test.Location.Y;
        if (direction == "right") 
        {
            for (int i = 0; i < 32; i++)
            {
                x++;
                Test.Location = new Point(x, y);
                Thread.Sleep(31);
            }
        }
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        int xmax = Screen.PrimaryScreen.Bounds.Width - 32;
        int ymax = Screen.PrimaryScreen.Bounds.Height - 32;
        if (e.KeyCode == Keys.Right && x < xmax) direction = "right";
        else if (e.KeyCode == Keys.Left && x > 0) direction = "left";
        else if …
Run Code Online (Sandbox Code Playgroud)

c# function wait

4
推荐指数
1
解决办法
2552
查看次数

标签 统计

c# ×1

function ×1

wait ×1