示例#1
0
        public static ThreadCancellable CallInterval(Int32 millisecondsInterval, Func <Boolean> func)
        {
            ThreadCancellable thread = new ThreadCancellable((obj) =>
            {
                CancellationToken cancelToken = (CancellationToken)obj;
                while (cancelToken.IsCancellationRequested == false)
                {
                    try
                    {
                        if (cancelToken.WaitHandle.WaitOne(millisecondsInterval) == true ||
                            func() == false)
                        {
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Write(LogType.Err, 1, e.ToString());
                    }
                }
            });

            thread.Start();

            return(thread);
        }
示例#2
0
        public static void Initialize()
        {
            _maxAliveSecond = Starter.CustomData.GetValue("UserManager/maxAliveSecond").ToInt32();

            _users = new Dictionary<Int32, UserData>();
            _thread = ThreadCancellable.CallPeriodically(1000, CheckExpiredUser);
        }
        public static ThreadCancellable CallInterval(Int32 millisecondsInterval, Func<Boolean> func)
        {
            ThreadCancellable thread = new ThreadCancellable((obj) =>
            {
                CancellationToken cancelToken = (CancellationToken)obj;
                while (cancelToken.IsCancellationRequested == false)
                {
                    try
                    {
                        if (cancelToken.WaitHandle.WaitOne(millisecondsInterval) == true ||
                            func() == false)
                            break;
                    }
                    catch (Exception e)
                    {
                        Logger.Write(LogType.Err, 1, e.ToString());
                    }
                }
            });
            thread.Start();

            return thread;
        }
示例#4
0
        private void OnConnected(Session session, Boolean connected)
        {
            if (connected == false)
            {
                TryConnect();
                return;
            }

            PacketRequest reqPacket = new PacketRequest(Protocol.GetID("SS_Register_Req"));
            reqPacket.PutInt32(ServerCatalog.MyServerInfo.Uid);
            SendAndResponse(reqPacket, (resPacket) =>
            {
                Logger.Write(LogType.Info, 2, "Connected to the AuthServer.");

                _threadRun = ThreadCancellable.CallPeriodically(1000, () =>
                {
                    PacketRequest ntfPacket = new PacketRequest(Protocol.GetID("SS_Traffic_Ntf"));
                    ntfPacket.PutInt32(Statistics.CCU);
                    SendPacket(ntfPacket);

                    return Connected;
                });
            });
        }
示例#5
0
        public static void Release()
        {
            _thread?.Cancel();
            _thread = null;

            _users.Clear();
        }
示例#6
0
 public void Release()
 {
     _thread?.Cancel();
     _thread = null;
     _ccu = 0;
 }
示例#7
0
 public void Initialize()
 {
     _ccu = 0;
     _thread = ThreadCancellable.CallInterval(1000, Run);
     _thread.Thread.Name = "UserManager";
 }
示例#8
0
 public void Initialize()
 {
     _thread = ThreadCancellable.CallInterval(1000, CheckExpiredItem);
     _thread.Thread.Name = "CacheBox";
 }