/// <summary> /// Handler for launching HDK Firmware Utility /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void launchFWUToolStripMenuItem_Click(object sender, EventArgs e) { if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.FW_UTIL_NAME)) { StartFWUtil(); } }
/// <summary> /// Handler for launching Unity campfire sample app /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void launchSampleSceneToolStripMenuItem_Click(object sender, EventArgs e) { if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.TEST_APP_NAME)) { StartTestApp(); } }
/// <summary> /// Handler for launching tracker viewer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void launchTrackerViewToolStripMenuItem_Click(object sender, EventArgs e) { if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.TRACKER_VIEW_NAME)) { StartTrackerView(); } }
static void Main(string[] args) { // Visual setup try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); } catch (InvalidOperationException e) { Debug.WriteLine("Unable to set text compatible text rendering default: " + e.Message + "\n" + e.StackTrace); } // If run with -startserver flag, try to start the server; if the server is already running, ignore this flag bool start_server_arg = args.Length == 1 && args[0] == "-startserver"; // Check whether the OSVR Server is already running bool server_running = OSVRProcessManager.ProcessInstanceIsRunning(Common.SERVICE_NAME); // Check whether another instance of the TrayApp is already running Process existing_trayapp_instance = OSVRProcessManager.ExistingTrayAppProcess(); bool trayapp_running = existing_trayapp_instance != null; // On Win7x64 Pro and potentially other operating systems, two instances of this application are for some reason // being launched on startup, despite only one entry existing in msconfig's startups tab. See OSVI-201 for details. // // When this situation occurs, this block will detect it and terminate the instance with the higher process ID. // This could also be solved with the sort of global system lock that used to be present here, but that had other issues. if (trayapp_running && DateTime.Now - existing_trayapp_instance.StartTime < TimeSpan.FromSeconds(1d)) { if (existing_trayapp_instance.Id < Process.GetCurrentProcess().Id) { Debug.WriteLine("Two instances launched at nearly the same time; terminating this one because it has a higher process ID."); return; } else { Debug.WriteLine("Two instances launched at nearly the same time; terminating other one because it has a higher process ID."); trayapp_running = false; } } /* * trayapp_running, start_server_arg, server_running: * no, yes, yes -> show message saying unmanaged server already running * no, no, yes -> show message saying unmanaged server already running * no, no, no -> vanilla * yes, yes, no -> terminate existing instance, launch server * no, yes, no -> launch server * yes, yes, yes -> terminate this instance, show message saying both server and trayapp are already running * yes, no, yes -> terminate this instance, show message saying trayapp already running * yes, no, no -> terminate this instance, show message saying trayapp already running */ bool terminate_this_instance = trayapp_running && (!start_server_arg || server_running); bool terminate_existing_instance = trayapp_running && start_server_arg && !server_running; bool launch_server = start_server_arg && !server_running; bool msg_unmanaged_server_already_running = !trayapp_running && server_running; bool msg_trayapp_already_running = trayapp_running && !start_server_arg; bool msg_both_already_running = trayapp_running && start_server_arg && server_running; if (msg_unmanaged_server_already_running) { Common.ShowMessageBox(Common.MSG_SERVER_ALREADY_RUNNING_UMANAGED, MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (msg_trayapp_already_running) { Common.ShowMessageBox(Common.MSG_TRAYAPP_ALREADY_RUNNING, MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (msg_both_already_running) { Common.ShowMessageBox(Common.MSG_TRAYAPP_AND_SERVER_ALREADY_RUNNING, MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (terminate_existing_instance) { try { existing_trayapp_instance.Kill(); } catch { Debug.WriteLine("Unable to kill existing TrayApp process with PID " + existing_trayapp_instance.Id + "!"); } } if (terminate_this_instance) { return; } #if (RUN_TESTRAIL) CommonTests.Run(); #endif using (OSVRIcon osvrIcon = new OSVRIcon()) { osvrIcon.Display(launch_server); Application.Run(); } }
public bool serverRunning() { ServerLastState = OSVRProcessManager.ProcessInstanceIsRunning(Common.SERVICE_NAME); return(ServerLastState); }