Added support for Silverlight and Mono (And more)

Also added:
* Join, Choice, and Pipe to SmartThreadPool.
* Local performance counters (for Mono, Silverlight, and WindowsCE)
This commit is contained in:
Ami Bar
2009-12-19 17:36:39 +02:00
parent d2c14da5ad
commit 760bc5d1a9
61 changed files with 2960 additions and 969 deletions
-40
View File
@@ -91,10 +91,6 @@ namespace WorkItemsGroupDemo
this.label19 = new System.Windows.Forms.Label();
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.panelWIGsCtrls = new System.Windows.Forms.Panel();
this.pcActiveThreads = new System.Diagnostics.PerformanceCounter();
this.pcInUseThreads = new System.Diagnostics.PerformanceCounter();
this.pcQueuedWorkItems = new System.Diagnostics.PerformanceCounter();
this.pcCompletedWorkItems = new System.Diagnostics.PerformanceCounter();
this.timerPoll = new System.Windows.Forms.Timer(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
@@ -125,10 +121,6 @@ namespace WorkItemsGroupDemo
this.groupWIGQueues.SuspendLayout();
this.groupBox7.SuspendLayout();
this.panelWIGsCtrls.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pcActiveThreads)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pcInUseThreads)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pcQueuedWorkItems)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pcCompletedWorkItems)).BeginInit();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@@ -962,30 +954,6 @@ namespace WorkItemsGroupDemo
this.panelWIGsCtrls.Size = new System.Drawing.Size(612, 105);
this.panelWIGsCtrls.TabIndex = 1;
//
// pcActiveThreads
//
this.pcActiveThreads.CategoryName = "SmartThreadPool";
this.pcActiveThreads.CounterName = "Active threads";
this.pcActiveThreads.InstanceName = "SmartThreadPoolDemo";
//
// pcInUseThreads
//
this.pcInUseThreads.CategoryName = "SmartThreadPool";
this.pcInUseThreads.CounterName = "In use threads";
this.pcInUseThreads.InstanceName = "SmartThreadPoolDemo";
//
// pcQueuedWorkItems
//
this.pcQueuedWorkItems.CategoryName = "SmartThreadPool";
this.pcQueuedWorkItems.CounterName = "Work Items in queue";
this.pcQueuedWorkItems.InstanceName = "SmartThreadPoolDemo";
//
// pcCompletedWorkItems
//
this.pcCompletedWorkItems.CategoryName = "SmartThreadPool";
this.pcCompletedWorkItems.CounterName = "Work Items processed";
this.pcCompletedWorkItems.InstanceName = "SmartThreadPoolDemo";
//
// timerPoll
//
this.timerPoll.Interval = 500;
@@ -1172,10 +1140,6 @@ namespace WorkItemsGroupDemo
this.groupWIGQueues.ResumeLayout(false);
this.groupBox7.ResumeLayout(false);
this.panelWIGsCtrls.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pcActiveThreads)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pcInUseThreads)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pcQueuedWorkItems)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pcCompletedWorkItems)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
@@ -1256,10 +1220,6 @@ namespace WorkItemsGroupDemo
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Panel panelWIGsCtrls;
private System.Windows.Forms.Button btnMode;
private System.Diagnostics.PerformanceCounter pcActiveThreads;
private System.Diagnostics.PerformanceCounter pcInUseThreads;
private System.Diagnostics.PerformanceCounter pcQueuedWorkItems;
private System.Diagnostics.PerformanceCounter pcCompletedWorkItems;
private System.Windows.Forms.Timer timerPoll;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
+79 -10
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using UsageControl;
@@ -28,6 +29,19 @@ namespace WorkItemsGroupDemo
private static readonly Color _wig2Color = Color.Green;
private static readonly Color _wig3Color = Color.Blue;
#if _WINDOWS
private System.Diagnostics.PerformanceCounter _pcActiveThreads;
private System.Diagnostics.PerformanceCounter _pcInUseThreads;
private System.Diagnostics.PerformanceCounter _pcQueuedWorkItems;
private System.Diagnostics.PerformanceCounter _pcCompletedWorkItems;
#endif
private Func<long> _getActiveThreads;
private Func<long> _getInUseThreads;
private Func<long> _getQueuedWorkItems;
private Func<long> _getCompletedWorkItems;
private class WigEntry
{
@@ -53,6 +67,7 @@ namespace WorkItemsGroupDemo
InitializeComponent();
InitSTP();
InitializeGUIPerformanceCounters();
UpdateControls(false);
UpdateModeControls();
@@ -60,11 +75,15 @@ namespace WorkItemsGroupDemo
private void InitSTP()
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
stpStartInfo.MaxWorkerThreads = (int)spinCon6.Value;
stpStartInfo.IdleTimeout = 5000;
stpStartInfo.PerformanceCounterInstanceName = "SmartThreadPoolDemo";
STPStartInfo stpStartInfo =
new STPStartInfo
{
StartSuspended = true,
MaxWorkerThreads = ((int)spinCon6.Value),
IdleTimeout = int.Parse(spinIdleTimeout.Text)*1000,
PerformanceCounterInstanceName = "SmartThreadPoolDemo",
EnableLocalPerformanceCounters = true,
};
_stp = new SmartThreadPool(stpStartInfo);
_wig1 = _stp.CreateWorkItemsGroup((int)spinCon1.Value);
@@ -93,6 +112,54 @@ namespace WorkItemsGroupDemo
}
}
private void InitializeGUIPerformanceCounters()
{
#if _WINDOWS
this._pcActiveThreads = new System.Diagnostics.PerformanceCounter();
this._pcInUseThreads = new System.Diagnostics.PerformanceCounter();
this._pcQueuedWorkItems = new System.Diagnostics.PerformanceCounter();
this._pcCompletedWorkItems = new System.Diagnostics.PerformanceCounter();
//
// pcActiveThreads
//
this._pcActiveThreads.CategoryName = "SmartThreadPool";
this._pcActiveThreads.CounterName = "Active threads";
this._pcActiveThreads.InstanceName = "SmartThreadPoolDemo";
//
// pcInUseThreads
//
this._pcInUseThreads.CategoryName = "SmartThreadPool";
this._pcInUseThreads.CounterName = "In use threads";
this._pcInUseThreads.InstanceName = "SmartThreadPoolDemo";
//
// pcQueuedWorkItems
//
this._pcQueuedWorkItems.CategoryName = "SmartThreadPool";
this._pcQueuedWorkItems.CounterName = "Work Items in queue";
this._pcQueuedWorkItems.InstanceName = "SmartThreadPoolDemo";
//
// pcCompletedWorkItems
//
this._pcCompletedWorkItems.CategoryName = "SmartThreadPool";
this._pcCompletedWorkItems.CounterName = "Work Items processed";
this._pcCompletedWorkItems.InstanceName = "SmartThreadPoolDemo";
_getActiveThreads = () => (long)_pcActiveThreads.NextValue();
_getInUseThreads = () => (long)_pcInUseThreads.NextValue();
_getQueuedWorkItems = () => (long)_pcQueuedWorkItems.NextValue();
_getCompletedWorkItems = () => (long)_pcCompletedWorkItems.NextValue();
#else
_getActiveThreads = delegate () { return _stp.PerformanceCountersReader.ActiveThreads; };
_getInUseThreads = delegate () { return _stp.PerformanceCountersReader.InUseThreads; };
_getQueuedWorkItems = delegate () { return _stp.PerformanceCountersReader.WorkItemsQueued; };
_getCompletedWorkItems = delegate () { return _stp.PerformanceCountersReader.WorkItemsProcessed; };
#endif
}
private void btnStart_Click(object sender, EventArgs e)
{
_running = !_running;
@@ -152,6 +219,8 @@ namespace WorkItemsGroupDemo
{
break;
}
Stopwatch stopwatch = Stopwatch.StartNew();
//while (stopwatch.ElapsedMilliseconds < workItemState.SleepDuration);
Thread.Sleep(workItemState.SleepDuration);
} while (_paused);
_workingStates.Remove(workItemState.QueueUsageEntry);
@@ -177,7 +246,7 @@ namespace WorkItemsGroupDemo
{
lblStatus6.Text = _stp.IsIdle ? "Idle" : "Working";
object[] statesWorking;
object [] statesWorking = null;
lock (_workingStates.SyncRoot)
{
statesWorking = new object[_workingStates.Count];
@@ -343,15 +412,15 @@ namespace WorkItemsGroupDemo
return;
}
int threadsInUse = (int)pcInUseThreads.NextValue();
int threadsInPool = (int)pcActiveThreads.NextValue();
int threadsInUse = (int)_getInUseThreads();
int threadsInPool = (int)_getActiveThreads();
lblThreadInUse.Text = threadsInUse.ToString();
lblThreadsInPool.Text = threadsInPool.ToString();
lblWaitingCallbacks.Text = pcQueuedWorkItems.NextValue().ToString(); //stp.WaitingCallbacks.ToString();
lblWaitingCallbacks.Text = _getQueuedWorkItems().ToString(); //stp.WaitingCallbacks.ToString();
usageThreadsInPool.Value1 = threadsInUse;
usageThreadsInPool.Value2 = threadsInPool;
lblWorkItemsCompleted.Text = pcCompletedWorkItems.NextValue().ToString();
lblWorkItemsCompleted.Text = _getCompletedWorkItems().ToString();
lblWorkItemsGenerated.Text = _workItemsGenerated.ToString();
usageHistorySTP.AddValues(threadsInUse, threadsInPool);
}
+3 -11
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{DC005A64-FAE9-4CFA-ADC8-F1D1FE7FE6CD}</ProjectGuid>
<OutputType>WinExe</OutputType>
@@ -21,7 +21,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;_WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -30,18 +30,10 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;_WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseCE|AnyCPU' ">
<OutputPath>bin\ReleaseCE\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />