Пример #1
0
        /// <inheritdoc />
        public void CreateBrowserInstances()
        {
            // wait a short while for the semaphore, if we can't get it then assume someone else is maintaining the pool
            if (this.syncLock.Wait(100))
            {
                try
                {
                    foreach (var pool in this.browserPools.Values)
                    {
                        for (int i = pool.InstanceCount; i < pool.MaxInstances; i++)
                        {
                            try
                            {
                                BrowserAbstract browser = this.factory.Create(pool.BrowserType);

                                Logger.WriteInfo(
                                    "Registering browser: {0} (PID {1} parent PID {2})",
                                    browser.GetType().Name,
                                    browser.ProcessId,
                                    browser.ParentProcessId);

                                pool.AddInstance(browser);
                            }
                            catch (Exception exception)
                            {
                                Logger.WriteWarning(
                                    exception,
                                    "Unexpected failure while creating a browser of type {0}",
                                    pool.BrowserType);
                            }
                        }
                    }
                }
                finally
                {
                    this.syncLock.Release();
                }
            }
        }