/// <summary>
        /// Runs the assembly with the specified arguments.xit
        /// </summary>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="environmentVariables">The environment variables.</param>
        /// <param name="args">The main arguments.</param>
        /// <param name="shadowCache">If [true], use shadow cache.</param>
        /// <param name="logger">The logger.</param>
        /// <returns>System.Int32.</returns>
        public int Run(string workingDirectory, Dictionary <string, string> environmentVariables, string[] args, bool shadowCache, NpClient <IServerLogger> callbackChannel)
        {
            lock (disposingLock)
            {
                if (isDisposed)
                {
                    callbackChannel.Proxy.OnLog("Error, server is being shutdown, cannot run Compiler", ConsoleColor.Red);
                    return(1);
                }
            }


            AppDomainShadow shadowDomain = null;

            try
            {
                shadowDomain = GetOrNew(shadowCache, IsCachingAppDomain);
                return(shadowDomain.Run(workingDirectory, environmentVariables, args, callbackChannel));
            }
            finally
            {
                if (shadowDomain != null)
                {
                    shadowDomain.EndRun();
                    if (!IsCachingAppDomain)
                    {
                        shadowDomain.Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// Get or create a new <see cref="AppDomainShadow"/>.
        /// </summary>
        /// <returns></returns>
        private AppDomainShadow GetOrNew(bool shadowCache, bool appdomainCache)
        {
            lock (appDomainShadows)
            {
                foreach (var appDomainShadow in appDomainShadows)
                {
                    if (appDomainShadow.ShadowCache == shadowCache && appDomainShadow.TryLock())
                    {
                        Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name);
                        return(appDomainShadow);
                    }
                }

                var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count;
                Console.WriteLine("Create new AppDomain {0}", newAppDomainName);
                var newAppDomain = new AppDomainShadow(newAppDomainName, entryAssemblyPath, mainAssemblyPath, shadowCache, nativeDllsPathOrFolderList.ToArray());
                newAppDomain.TryLock();

                if (appdomainCache)
                {
                    appDomainShadows.Add(newAppDomain);
                }
                return(newAppDomain);
            }
        }