Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static void Initialize()
        {
            _maxAliveSecond = Starter.CustomData.GetValue("UserManager/maxAliveSecond").ToInt32();

            _users = new Dictionary<Int32, UserData>();
            _thread = ThreadCancellable.CallPeriodically(1000, CheckExpiredUser);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 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;
                });
            });
        }
Ejemplo n.º 5
0
        public static void Release()
        {
            _thread?.Cancel();
            _thread = null;

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