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); }
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; }
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; }); }); }
public static void Release() { _thread?.Cancel(); _thread = null; _users.Clear(); }
public void Release() { _thread?.Cancel(); _thread = null; _ccu = 0; }
public void Initialize() { _ccu = 0; _thread = ThreadCancellable.CallInterval(1000, Run); _thread.Thread.Name = "UserManager"; }
public void Initialize() { _thread = ThreadCancellable.CallInterval(1000, CheckExpiredItem); _thread.Thread.Name = "CacheBox"; }