static ServicePointManager() { #if !MONOTOUCH #if NET_2_0 && CONFIGURATION_DEP object cfg = ConfigurationManager.GetSection(configKey); ConnectionManagementSection s = cfg as ConnectionManagementSection; if (s != null) { manager = new ConnectionManagementData(null); foreach (ConnectionManagementElement e in s.ConnectionManagement) { manager.Add(e.Address, e.MaxConnection); } defaultConnectionLimit = (int)manager.GetMaxConnections("*"); return; } #endif manager = (ConnectionManagementData)ConfigurationSettings.GetConfig(configKey); if (manager != null) { defaultConnectionLimit = (int)manager.GetMaxConnections("*"); } #endif }
static ServicePointManager() { #if !MOBILE #if CONFIGURATION_DEP object cfg = ConfigurationManager.GetSection(configKey); ConnectionManagementSection s = cfg as ConnectionManagementSection; if (s != null) { manager = new ConnectionManagementData(null); foreach (ConnectionManagementElement e in s.ConnectionManagement) { manager.Add(e.Address, e.MaxConnection); } defaultConnectionLimit = (int)manager.GetMaxConnections("*"); return; } #endif #pragma warning disable 618 manager = (ConnectionManagementData)ConfigurationSettings.GetConfig(configKey); #pragma warning restore 618 if (manager != null) { defaultConnectionLimit = (int)manager.GetMaxConnections("*"); } #endif }
void Set(string[] conf) { if (conf.Length < 3) { return; } try { ConfigType config = (ConfigType)Enum.Parse(typeof(ConfigType), conf[1]); switch (config) { case ConfigType.MaxConnections: object connMgt = ConfigurationManager.OpenMachineConfiguration().GetSectionGroup("system.net").Sections["connectionManagement"]; ConnectionManagementSection connMgtSection = connMgt as ConnectionManagementSection; connMgtSection.ConnectionManagement.Clear(); connMgtSection.ConnectionManagement.Add(new ConnectionManagementElement("*", int.Parse(conf[2]))); break; case ConfigType.MaxIOThreads: int iomiot, wmiot; ThreadPool.GetMaxThreads(out wmiot, out iomiot); ThreadPool.SetMaxThreads(wmiot, int.Parse(conf[2])); break; case ConfigType.MaxWorkerThreads: int iomwt, wmwt; ThreadPool.GetMaxThreads(out wmwt, out iomwt); ThreadPool.SetMaxThreads(int.Parse(conf[2]), iomwt); break; case ConfigType.RequestQueueLimit: ProcessModelSection pms = (ProcessModelSection)ConfigurationManager.OpenMachineConfiguration().GetSectionGroup("system.web").Sections["processModel"]; pms.RequestQueueLimit = int.Parse(conf[2]); break; case ConfigType.ParallelDistantRequestValue: Config.ParallelRequests = int.Parse(conf[2]); break; case ConfigType.Timeout: Config.Timeout = int.Parse(conf[2]); break; case ConfigType.ReadWriteTimeout: Config.ReadWriteTimeout = int.Parse(conf[2]); break; case ConfigType.AvailableIOThreads: case ConfigType.AvailableWorkerThreads: default: break; } } catch (Exception e) { } }
Dictionary <string, string> GetConfigs() { Dictionary <string, string> configs = new Dictionary <string, string>(); #region Custom configs configs.Add("ParallelDistantRequestValue", Config.ParallelRequests.ToString()); #endregion #region ProcessModel ProcessModelSection pms = (ProcessModelSection)ConfigurationManager.OpenMachineConfiguration().GetSectionGroup("system.web").Sections["processModel"]; configs.Add("RequestQueueLimit", pms.RequestQueueLimit.ToString()); #endregion #region HttpRuntime RequestQueue HttpRuntime runtime = (HttpRuntime)((FieldInfo)typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static)).GetValue(null); object requestQueue = ((FieldInfo)typeof(HttpRuntime).GetField("_requestQueue", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField)).GetValue(runtime); Assembly sweb = Assembly.Load(new AssemblyName("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")); Type RequestQueue = sweb.GetType("System.Web.RequestQueue");//.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); //System.Reflection.FieldInfo[] configs.Add("runtimeQueueCount", RequestQueue.GetField("_count", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField).GetValue(requestQueue).ToString()); #endregion #region Connection management object connMgt = ConfigurationManager.OpenMachineConfiguration().GetSectionGroup("system.net").Sections["connectionManagement"]; ConnectionManagementSection connMgtSection = connMgt as ConnectionManagementSection; int maxConns = 0; if (connMgtSection != null && connMgtSection.ConnectionManagement.Count > 0) { maxConns = connMgtSection.ConnectionManagement[0].MaxConnection; } else { maxConns = DefaultMaxConnection; } configs.Add("maxconnections", maxConns.ToString()); #endregion #region Thread pool available threads int wt, iot; ThreadPool.GetAvailableThreads(out wt, out iot); configs.Add("AvailableWorkerThreads", wt.ToString()); configs.Add("AvailableIOThreads", iot.ToString()); #endregion #region Thread pool Max threads int mwt, miot; ThreadPool.GetMaxThreads(out mwt, out miot); configs.Add("MaxWorkerThreads", mwt.ToString()); configs.Add("MaxIOThreads", miot.ToString()); #endregion #region Thread pool Max threads int minwt, miniot; ThreadPool.GetMinThreads(out minwt, out miniot); configs.Add("MinWorkerThreads", minwt.ToString()); configs.Add("MinIOThreads", miniot.ToString()); #endregion #region Timeout configs.Add("Timeout", Config.Timeout.ToString()); configs.Add("ReadWriteTimeout", Config.ReadWriteTimeout.ToString()); #endregion return(configs); }