在foreach循环中停留时间重置?

时间:2013-06-13 03:13:31

标签: c# foreach

事情是staytime永远不会进入0但会断开连接。

需要做staytime吗?

foreach (var playe in w_server.OnlineConnections)
{
        if (staytime > 1 * 20000 && play.Value.Map == "Rest")
        {
            staytime = Server.tickcount.ElapsedMilliseconds;
            w_server.Disconnect(play.Value.client.connection);
            play.Value.Map = "Village1";
            staytime = 0;
        }
}

1 个答案:

答案 0 :(得分:0)

我认为您需要在playe中将变量play更改为foreach,然后在staytime之前更改if condition值。如果您刚刚为0分配了值,那么如何才能staytime

foreach (var play in w_server.OnlineConnections)
{
    staytime = Server.tickcount.ElapsedMilliseconds;

    if (staytime > 1 * 20000 && play.Value.Map == "Rest")
    {
        w_server.Disconnect(play.Value.client.connection);
        play.Value.Map = "Village1";
        staytime = 0;
    }
}