Пример #1
0
        // Stops any current tasks and unloads the PSAppDomain.  Throws an exception if the domain can't be unloaded
        public void Shutdown()
        {
            if (task != null)
            {
                task.Stop();
                task = null;
            }

            if (PSAppDomain != null)
            {
                AppDomain.Unload(PSAppDomain);
                PSAppDomain = null;
            }
        }
Пример #2
0
        public void Initialize(string PSScriptBlock)
        {
            PSAppDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), AppDomain.CurrentDomain.Evidence);

            // Create a new PSTask object in a separate app domain.
            // Because PSExecutionitem implements MarshalByRefObject, CreateInstanceAndUnwrap returns a "proxy" object that we can use to query info about the remote object
            task = (PSExecutionItem)PSAppDomain.CreateInstanceAndUnwrap(
                Assembly.GetExecutingAssembly().FullName,
                typeof(PSExecutionItem).FullName,
                false,
                BindingFlags.Default,
                default(Binder),
                new object[] { PSScriptBlock },      // PSExecutionitem constructor arguments
                default(CultureInfo),
                null,
                AppDomain.CurrentDomain.Evidence
                );
        }