Пример #1
0
            public void Stop(bool callbackOnFinished)
            {
                lock (workerlock)
                {
                    if (workerrunning)
                    {
                        if (workerconnected)
                        {
                            clipboard.UnregisterClient();
                            workerconnected = false;
                        }
                        comms.CloseMessagePipes();

                        wmisession.Log("Stopping worker process " + worker.DangerousGetHandle().ToString());
                        registeredWorkerWaiter.Unregister(null);
                        try
                        {
                            // Don't kill the process.  If we have closed the Pipes, then that should be sufficient
                            // Win32Impl.KillProcess(worker.DangerousGetHandle(), 1);
                        }
                        catch
                        {
                            //If we fail to kill, we want to ignore this fact.  An error is already logged.
                        }
                        workerrunning = false;
                        if (callbackOnFinished)
                        {
                            wphandler.WorkerProcessFinished();
                        }
                    }
                }
            }
Пример #2
0
            public WorkerProcess(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler, IWorkerProcessHandler wphandler, IntPtr consoletoken)
            {
                this.clipboard        = clipboard;
                this.wmisession       = wmisession;
                this.exceptionhandler = exceptionhandler;
                this.wphandler        = wphandler;

                workerlock = new object();
                try
                {
                    comms = new CommServer(this);
                }
                catch (Exception e)
                {
                    wmisession.Log("Comms server failed to start:" + e.ToString());
                    throw;
                }
                try
                {
                    AddToXDIgnoreApplicationList();
                    string path     = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "Install_Dir", "");
                    string fullpath = string.Format("{0}\\" + Branding.Instance.getString("FILENAME_dpriv"), path);
                    string cmdline  = string.Format(Branding.Instance.getString("FILENAME_dpriv") + " {0}", comms.secret);
                    this.worker            = new SafeWaitHandle(Win32Impl.CreateUserProcess(consoletoken, fullpath, cmdline), true);
                    workerWaiter           = new ProcessWaitHandle(this.worker);
                    registeredWorkerWaiter = ThreadPool.RegisterWaitForSingleObject(workerWaiter, handleWorker, null, Timeout.Infinite, true);
                    this.workerrunning     = true;
                    wmisession.Log("Worker Process spawned");
                }
                catch (Exception e)
                {
                    wmisession.Log("Worker process spawn exception : " + e.ToString());
                    comms.CloseMessagePipes();

                    throw;
                }
            }