public ObjectPool(Func <T> objectGen) { if (objectGen == null) { throw new ArgumentNullException("objectGen"); } objects = new System.Collections.Concurrent.ConcurrentStack <T>(); objectGenerator = objectGen; }
/// <summary> /// 创建ConnectionPool实例 /// </summary> /// <param name="master">主连接。</param> public ConnectionPool(IConnection master) { _master = master; _list = new System.Collections.Concurrent.ConcurrentStack <IConnection>(); if (!_master.MultipleActiveResultSets) { Push(_master); } }
public virtual void HttpGetAsync(IEnumerable <string> urls) { UseCache = false; int ThreadNum = 4; System.Collections.Concurrent.ConcurrentStack <string> stack = new System.Collections.Concurrent.ConcurrentStack <string>(urls.Distinct()); List <System.Threading.Tasks.Task <List <DownloadData> > > tasks = new List <System.Threading.Tasks.Task <List <DownloadData> > >(); for (int i = 0; i < ThreadNum; i++) { var task = System.Threading.Tasks.Task.Factory.StartNew <List <DownloadData> >((n) => { List <DownloadData> list = new List <DownloadData>(); var c = this.GetCopy(); while (true) { string url = string.Empty; if (stack.TryPop(out url)) { DownloadData dd = new DownloadData() { Url = url, HTML = c.HttpGet(url) }; list.Add(dd); } else { break; } } c.Dispose(); return(list); }, System.Threading.Tasks.TaskCreationOptions.LongRunning); if (task != null) { tasks.Add(task); } } System.Threading.Tasks.Task.WaitAll(tasks.ToArray()); foreach (var item in tasks.SelectMany(n => n.Result)) { casheDic.GetValueOrAdd(item.Url, item.HTML); } UseCache = true; }
public SunburstDrillDownManager(IEnumerable <DataItem> orignal) { this.Orignal = orignal.ToArray(); this.CurrentItems = this.Orignal; History = new System.Collections.Concurrent.ConcurrentStack <SunburstDrillDownHistory>(); History.Push( new SunburstDrillDownHistory() { Items = this.CurrentItems, } ); if (OnDrillDownChanged != null) { this.OnDrillDownChanged(this, new EventArgs()); } }
void InitPools() { _ReadBufferSize = option.ReadBufSize; _SendBufferSize = option.WriteBufSize; poolEventArgs = new System.Collections.Concurrent.ConcurrentStack <SocketAsyncEventArgs>(); for (var i = 0; i < option.ListenLinkBufSize * 2; i++) { var args = new SocketAsyncEventArgs(); args.Completed += OnCompleted; poolEventArgs.Push(args); } poolLinks = new System.Collections.Concurrent.ConcurrentStack <LinkInfo>(); for (var i = 0; i < option.ListenLinkBufSize; i++) { poolLinks.Push(GetFreeLink()); } }
public IEnumerable <OUT> Select <OUT>(Func <T, OUT> action) { var c = new CountdownEvent(_maxDOP); var ret = new System.Collections.Concurrent.ConcurrentStack <OUT>(); var ie = _items.GetEnumerator(); for (int i = 0; i < _maxDOP; i++) { Task.Factory.StartNew(delegate { try { T current = default(T); while (true) { lock (ie) { if (!ie.MoveNext()) { break; } current = ie.Current; } ret.Push(action(current)); } } finally { c.Signal(1); } }, _islongrunnig ? TaskCreationOptions.LongRunning : TaskCreationOptions.None); } ; c.Wait(); return(ret); }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="connectionInfo"/>, <paramref name="minRunspaces"/> /// and <paramref name="maxRunspaces"/> /// </summary> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="host">Host associated with this runspacepool</param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <param name="connectionInfo">The RunspaceConnectionInfo object /// which identifies this runspace pools connection to the server /// </param> /// <param name="name">Session name.</param> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> /// <exception cref="ArgumentException"> /// ConnectionInfo specified is null /// </exception> internal RemoteRunspacePoolInternal(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null) : base(minRunspaces, maxRunspaces) { if (connectionInfo == null) { throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo"); } PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, instanceId.ToString(), minPoolSz.ToString(CultureInfo.InvariantCulture), maxPoolSz.ToString(CultureInfo.InvariantCulture)); _connectionInfo = connectionInfo.InternalCopy(); this.host = host; ApplicationArguments = applicationArguments; AvailableForConnection = false; DispatchTable = new DispatchTable<object>(); _runningPowerShells = new System.Collections.Concurrent.ConcurrentStack<PowerShell>(); if (!string.IsNullOrEmpty(name)) { this.Name = name; } CreateDSHandler(typeTable); }
/// <summary> /// Create a runspacepool object in the disconnected state. /// </summary> /// <param name="instanceId">Identifies remote session to connect.</param> /// <param name="name">Friendly name for runspace pool.</param> /// <param name="isDisconnected">Indicates whether the runspacepool is disconnected.</param> /// <param name="connectCommands">Array of commands associated with this runspace pool.</param> /// <param name="connectionInfo">Connection information for remote server.</param> /// <param name="host">PSHost object.</param> /// <param name="typeTable">TypeTable for object serialization/deserialization.</param> internal RemoteRunspacePoolInternal(Guid instanceId, string name, bool isDisconnected, ConnectCommandInfo[] connectCommands, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) : base(1, 1) { if (instanceId == null) { throw PSTraceSource.NewArgumentNullException("RunspacePool Guid"); } if (connectCommands == null) { throw PSTraceSource.NewArgumentNullException("ConnectCommandInfo[]"); } if (connectionInfo == null) { throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo"); } if (connectionInfo is WSManConnectionInfo) { _connectionInfo = connectionInfo.InternalCopy(); } else { Dbg.Assert(false, "ConnectionInfo must be WSManConnectionInfo"); } // Create the runspace pool object to have the same instanceId as the remote session. this.instanceId = instanceId; // This indicates that this is a disconnected remote runspace pool and min/max values // are currently unknown. These values will be updated once the object is connected. this.minPoolSz = -1; this.maxPoolSz = -1; PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, instanceId.ToString(), minPoolSz.ToString(CultureInfo.InvariantCulture), maxPoolSz.ToString(CultureInfo.InvariantCulture)); ConnectCommands = connectCommands; this.Name = name; this.host = host; DispatchTable = new DispatchTable<object>(); _runningPowerShells = new System.Collections.Concurrent.ConcurrentStack<PowerShell>(); // Create this object in the disconnected state. SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Disconnected, null)); CreateDSHandler(typeTable); AvailableForConnection = isDisconnected; }
public PluginManager(string directory) { this._directory = directory; _plugins = new System.Collections.Concurrent.ConcurrentStack<BasePlugin> (); }