protected override void OnDestroy() { base.OnDestroy(); bIsWebSocketHandlerOn = false; if (wsClient != null) { wsClient.CloseAsync(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "AdSubApp closed", System.Threading.CancellationToken.None).Wait(1000); wsClient.Dispose(); wsClient = null; } if (WebSocketThread != null) { WebSocketThread.Dispose(); WebSocketThread = null; } bIsHeartBeatThreadOn = false; if (HeartBeatThread != null) { HeartBeatThread.Dispose(); HeartBeatThread = null; } bIsProgramControlThreadOn = false; bIsProgramLoop = false; if (ProgramControlThread != null) { ProgramControlThread.Dispose(); ProgramControlThread = null; } CActivityManager.GetInstence().FinishAllActivity(); Settings.RuntimeLog.Info("OnDestroy"); }
public void StartHeartBeatThread(int heartbeatSeconds) { _log.Debug("Starting new heartbeat thread"); _heartBeatRunner = new HeartBeatThread(ProtocolWriter, heartbeatSeconds * 1000); _heartBeatThread = new Thread(new ThreadStart(_heartBeatRunner.Run)); _heartBeatThread.Name = "HeartBeat"; _heartBeatThread.Start(); }
/* Called when the activity is first created. */ protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //// 隐藏标题栏 //this.RequestWindowFeature(WindowFeatures.NoTitle); //// 隐藏状态栏 //this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); //// 将背景设置为空 //this.Window.SetBackgroundDrawable(null); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // 判断SD卡是否存在 if (Android.OS.Environment.ExternalStorageState == Android.OS.Environment.MediaMounted) { // 设置APP目录 Settings.AppPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/" + GetString(Resource.String.ApplicationName); using (File file = new File(Settings.AppPath)) { if (!file.Exists()) { bool bSuccess = file.Mkdirs(); // If failed, do something //this.Finish(); } } } else // SD卡不存在 { // 设置为当前目录 Settings.AppPath = "./" + GetString(Resource.String.ApplicationName); } // 心跳线程 if (HeartBeatThread == null) { HeartBeatThread = new Java.Lang.Thread(() => { bIsHeartBeatThreadOn = true; while (bIsHeartBeatThreadOn) { System.Threading.Thread.Sleep(Settings.HeartBeatRate); MemoryCheck(); HeartBeat(); } }); } if (!HeartBeatThread.IsAlive) { HeartBeatThread.Start(); } // 初始化首页布局 InitMainLayout(); }
public void StopHeartBeat() { if ((HeartBeatThread.ThreadState & ThreadState.WaitSleepJoin) != 0 || HeartBeatThread.ThreadState == ThreadState.Running) { HeartBeatThread.Abort(); HeartBeatThread.Join(); } }
protected override void OnDestroy() { base.OnDestroy(); bIsHeartBeatThreadOn = false; if (HeartBeatThread != null) { HeartBeatThread.Dispose(); HeartBeatThread = null; } CActivityManager.GetInstence().FinishAllActivity(); }
static void Main(string[] args) { Console.WindowWidth = 60; Connection.FirstConnect(); //connect to server Socket clientSocket = Connection.cliSocket; while (true) { //default state FirstUI(); string command = GetCommand(); //login state if (command.Equals("LOGIN")) { //try login LogIn(clientSocket); bool loginResult = LogInAccept(clientSocket); if (loginResult) { string lobbyCommand = String.Empty; HeartBeatThread hb = new HeartBeatThread(); // hb.StartListen(); //login success do { //lobby state LobbyUI(); lobbyCommand = GetCommand(); switch (lobbyCommand) { case "LIST": GetList(); break; case "JOIN": Console.Write("Select Room Number :"); int roomNum = Convert.ToInt32(Console.ReadLine()); JoinRoom(clientSocket, roomNum); break; case "CREATE": int roomNumber = CreateRoom(clientSocket); if (roomNumber == -1) { Console.WriteLine("Can not create new room"); } else { Console.WriteLine("Create Room " + roomNumber); JoinRoom(clientSocket, roomNumber); } break; case "LOGOUT": LogOut(clientSocket); //logout success Console.WriteLine("Logout"); break; default: Console.WriteLine("Invalid Command : " + lobbyCommand); break; } } while (!lobbyCommand.Equals("LOGOUT")); } else { continue; } }//login state else if (command.Equals("EXIT")) { clientSocket.Close(); Environment.Exit(0); }//exit else { Console.WriteLine("Invalid Command"); } //Login State End } //Application End } //main ends
/* Called when the activity is first created. */ protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // 隐藏标题栏 this.RequestWindowFeature(WindowFeatures.NoTitle); // 隐藏状态栏 this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); // 将背景设置为空 this.Window.SetBackgroundDrawable(null); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // 获取启动方式 string mode = null; if (Intent.Extras != null) { mode = Intent.Extras.GetString("mode"); } // 解析启动方式 if (ParseMode(mode) == 1) { // 开机自启动:未完全生效,后台运行 // 故重启! //RestartApp(); //// 重启后亦不生效,自杀后,通过守护进程开启 //Settings.RuntimeLog.Info("重启后亦不生效,自杀后,通过守护进程开启"); //Daemon(); // 关闭前,查看守护进程 //Finish(); //System.Threading.Thread.Sleep(8); //Android.OS.Process.KillProcess(Android.OS.Process.MyPid()); //return; } // 节目控制线程 if (ProgramControlThread == null) { ProgramControlThread = new Java.Lang.Thread(() => { bIsProgramControlThreadOn = true; while (bIsProgramControlThreadOn) { System.Threading.Thread.Sleep(2000); ProgramControl(); } }); } if (!ProgramControlThread.IsAlive) { ProgramControlThread.Start(); } // 心跳线程 if (HeartBeatThread == null) { HeartBeatThread = new Java.Lang.Thread(() => { bIsHeartBeatThreadOn = true; while (bIsHeartBeatThreadOn) { System.Threading.Thread.Sleep(Settings.HeartBeatRate); MemoryCheck(); HeartBeat(); //if (IsTimePointIn(DateTime.UtcNow)) if (IsTimePointIn(DateTime.Now)) { // 01:30~6:30 关闭程序 Settings.RuntimeLog.Info("01:30~6:30 关闭程序"); Daemon(); // 关闭前,查看守护进程 Finish(); System.Threading.Thread.Sleep(8); Android.OS.Process.KillProcess(Android.OS.Process.MyPid()); } } }); } if (!HeartBeatThread.IsAlive) { HeartBeatThread.Start(); } //// WebSocket线程 //if (WebSocketThread == null) //{ // WebSocketThread = new Java.Lang.Thread(() => // { // WebSocketHandler(); // }); //} //if (!WebSocketThread.IsAlive) //{ // WebSocketThread.Start(); //} }