/// <summary> /// Check that the process is running and log the time /// </summary> private void PollProcess() { TimeLastPolled = DateTime.Now; List <Process> currentProcesses = GetCurrentProcesses(); if (MyProcess == null) { //Find my process Process matchedProcess = currentProcesses.Find(x => x.ProcessName == ProcessName); if (matchedProcess == null) { //Assume that my process is the first application that's now running that wasn't running before matchedProcess = currentProcesses.Find(x => !PreRunProcesses.Contains(x.ProcessName)); } MyProcess = matchedProcess; if (MyProcess == null) { //If process still couldn't be found, it may have failed to run if (RunTime.TotalSeconds > AllowedLaunchTime) { Errors.Add("Process could not be found. It likely failed to launch: " + ProcessName); TimeLastPolled = null; EndProcessListener(); } return; } else { ProcessName = MyProcess.ProcessName; //TODO: Focus the process window? } } //Check that the process is running Process runningProcess = currentProcesses.Find(x => x.ProcessName == ProcessName); if (runningProcess == null) { //Process is not running EndProcessListener(); return; } OnPoll?.Invoke(this, EventArgs.Empty); }
protected override Task Poll() { Schedule(() => OnPoll?.Invoke()); return(base.Poll()); }
private void InitHubEvents() { _hubConnection.On <string>("UpdateOnlineUsers", (message) => { OnOnlineUsersUpdated?.Invoke(message.FromJson <List <User> >()); }); _hubConnection.On <int>("UpdateBalance", (balance) => { OnBalanceUpdated?.Invoke(balance); }); _hubConnection.On <string>("IncomingCall", (connectionId) => { OnIncomingCall?.Invoke(connectionId); }); _hubConnection.On <string>("CallAccepted", (connectionId) => { OnCallAccepted?.Invoke(connectionId); }); _hubConnection.On <string>("CallDeclined", (message) => { OnCallDeclined?.Invoke(message.FromJson <UserActionMessage>()); }); _hubConnection.On <string>("CallEnded", (message) => { OnCallEnded?.Invoke(message.FromJson <UserActionMessage>()); }); _hubConnection.On <string>("CallDenied", (message) => { OnCallDenied?.Invoke(message.FromJson <ServerActionMessage>()); }); _hubConnection.On <string>("Poll", (message) => { OnPoll?.Invoke(message.FromJson <PollMessage>()); }); _hubConnection.On <string, string>("ReceiveSignal", (connectionId, data) => { OnSignalReceived?.Invoke(connectionId, data); }); _hubConnection.On <string>("UpdateUsers", (message) => { OnUsersUpdated?.Invoke(message.FromJson <List <User> >()); }); _hubConnection.On <string>("UpdateCalls", (message) => { OnCallsUpdated?.Invoke(message.FromJson <List <UserCall> >()); }); _hubConnection.On <string>("CallAborted", (message) => { OnCallAborted?.Invoke(message.FromJson <ServerActionMessage>()); }); }