/// <summary> /// Ensures that the mainwindow of the primary tailviewer is brought to the front. /// Doesn't do anything when it already is. /// Doesn't do anything when the given process doesn't exist (anymore) /// </summary> public static void BringToFront() { try { ExclusiveMutex.ShowMainWindow(); } catch (Exception e) { Console.WriteLine("Caught unexpected exception: {0}", e); } }
/// <summary> /// Instructs the given tailviewer process to open and/or show the given data source /// </summary> /// <param name="args">The commandline arguments as given to Main()</param> public static void OpenFile(string[] args) { try { var arguments = ArgumentParser.TryParse(args); if (arguments.FileToOpen != null) { ExclusiveMutex.OpenFile(arguments.FileToOpen); } } catch (Exception e) { Console.WriteLine("Caught unexpected exception: {0}", e); } }
/// <summary> /// Tries to acquire an exclude mutex until: /// - an exclusive mutex was acquired /// - the timeout elapsed /// </summary> /// <returns>The acquired mutex or null if another process holds the mutex</returns> public static IMutex AcquireMutex(TimeSpan timeout) { DateTime start = DateTime.Now; TimeSpan elapsed; do { var mutex = ExclusiveMutex.TryAcquire(); if (mutex != null) { return(mutex); } Thread.Sleep(TimeSpan.FromMilliseconds(1)); elapsed = DateTime.Now - start; } while (elapsed < timeout); return(null); }
/// <summary> /// Tries to acquire an exclude mutex. /// </summary> /// <returns>The acquired mutex or null if another process holds the mutex</returns> public static IMutex AcquireMutex() { return(ExclusiveMutex.TryAcquire()); }