Beispiel #1
0
        /// <summary>
        /// Retrieve the .exe file path from a process id
        /// </summary>
        /// <param name="processId">The process id</param>
        /// <returns>The full path to the .exe file</returns>
        internal static string GetExecutablePath(int processId)
        {
            if (CoreHelper.IsUnitTesting())
            {
                return(@"C:\Windows\explorer.exe");
            }

            var buffer   = new StringBuilder(1024);
            var hprocess = NativeMethods.OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, processId);

            if (hprocess != IntPtr.Zero)
            {
                try
                {
                    var size = buffer.Capacity;
                    if (NativeMethods.QueryFullProcessImageName(hprocess, 0, buffer, out size))
                    {
                        return(buffer.ToString());
                    }
                }
                finally
                {
                    NativeMethods.CloseHandle(hprocess);
                }
            }

            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
Beispiel #2
0
 protected override void OnPropertyChanged(PropertyChangedEventArgs e)
 {
     if (!_suppressNotification)
     {
         if (SynchronizationContext.Current == _synchronizationContext || CoreHelper.IsUnitTesting())
         {
             // Execute the PropertyChanged event on the current thread
             RaisePropertyChanged(e);
         }
         else
         {
             // Raises the PropertyChanged event on the creator thread
             _synchronizationContext.Send(RaisePropertyChanged, e);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Initialize and confirm that the class is setted up.
        /// </summary>
        private static void Initialize()
        {
            if (_dispatchers == null)
            {
                _dispatchers = new List <Dispatcher>();

                if (CoreHelper.IsUnitTesting())
                {
                    // Unit tests
                    Dispatcher.CurrentDispatcher.ShutdownStarted += Application_Exit;
                }
                else
                {
                    // Real execution
                    Application.Current.Exit += Application_Exit;
                }
            }
        }