From 5c15d43942100071489f32eea407a9817b76f5e9 Mon Sep 17 00:00:00 2001
From: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Date: Wed, 3 Jun 2026 21:10:18 -0700
Subject: [PATCH] Reinstate supplemental remarks
---
.../EventSource/Overview/Project.csproj | 9 +
.../EventSource/Overview/program2.cs | 199 +++++++++
.../Overview/Project.csproj | 12 +
.../Overview/averagetimer32.cs | 370 +++++++++++++++++
.../Overview/numberofitems32.cs | 137 ++++++
.../Overview/numberofitems64.cs | 134 ++++++
.../Overview/program.cs | 155 +++++++
.../Overview/rateofcountspersecond32.cs | 159 +++++++
.../Overview/rateofcountspersecond64.cs | 159 +++++++
.../Overview/rawfraction.cs | 172 ++++++++
.../EventSource/Overview/Project.vbproj | 8 +
.../EventSource/Overview/program.vb | 36 ++
.../EventSource/Overview/program1.vb | 118 ++++++
.../Overview/Project.vbproj | 12 +
.../Overview/averagecount32.vb | 149 +++++++
.../Overview/averagetimer32.vb | 392 ++++++++++++++++++
.../Overview/elapsedtime.vb | 237 +++++++++++
.../Overview/numberofitems32.vb | 131 ++++++
.../Overview/numberofitems64.vb | 126 ++++++
.../Overview/program.vb | 153 +++++++
.../Overview/rateofcountspersecond32.vb | 151 +++++++
.../Overview/rateofcountspersecond64.vb | 151 +++++++
.../Overview/rawfraction.vb | 162 ++++++++
.../Matrix/Overview/Class1.vb | 128 ++++++
.../Matrix/Overview/Project.vbproj | 9 +
.../ExpandoObject/Overview/Project.vbproj | 8 +
.../ExpandoObject/Overview/module1.vb | 109 +++++
xml/System.Data/CommandBehavior.xml | 21 +-
xml/System.Data/DataColumn.xml | 296 ++++++++++++-
xml/System.Data/DataSet.xml | 36 +-
xml/System.Data/DataTable.xml | 39 +-
.../EventSource.xml | 69 ++-
.../EventWrittenEventArgs.xml | 24 +-
.../PerformanceCounterType.xml | 135 +++++-
xml/System.Diagnostics/ProcessStartInfo.xml | 26 +-
xml/System.Drawing.Drawing2D/Matrix.xml | 46 +-
xml/System.Dynamic/ExpandoObject.xml | 128 +++++-
37 files changed, 4396 insertions(+), 10 deletions(-)
create mode 100644 snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/Project.csproj
create mode 100644 snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/Project.csproj
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/program.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.cs
create mode 100644 snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.cs
create mode 100644 snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/Project.vbproj
create mode 100644 snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program.vb
create mode 100644 snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program1.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/Project.vbproj
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagecount32.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/elapsedtime.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/program.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.vb
create mode 100644 snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.vb
create mode 100644 snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Class1.vb
create mode 100644 snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Project.vbproj
create mode 100644 snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/Project.vbproj
create mode 100644 snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb
diff --git a/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/Project.csproj b/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/Project.csproj
new file mode 100644
index 00000000000..22dd9034898
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/Project.csproj
@@ -0,0 +1,9 @@
+
+
+
+ Library
+ net10.0
+ true
+
+
+
diff --git a/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs b/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs
new file mode 100644
index 00000000000..d8021c6f89f
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs
@@ -0,0 +1,199 @@
+//
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Tracing;
+
+namespace Demo
+{
+ //
+ public interface IMyLogging
+ {
+ void Error(int errorCode, string message);
+ void Warning(string message);
+ }
+
+ public sealed class MySource : EventSource, IMyLogging
+ {
+ public static MySource Log = new();
+
+ [Event(1)]
+ public void Error(int errorCode, string message) => WriteEvent(1, errorCode, message);
+
+ [Event(2)]
+ public void Warning(string message) => WriteEvent(2, message);
+ }
+ //
+
+ //
+ public abstract class UtilBaseEventSource : EventSource
+ {
+ protected UtilBaseEventSource()
+ : base()
+ { }
+
+ protected UtilBaseEventSource(bool throwOnEventWriteErrors)
+ : base(throwOnEventWriteErrors)
+ { }
+
+ // helper overload of WriteEvent for optimizing writing an event containing
+ // payload properties that don't align with a provided overload. This prevents
+ // EventSource from using the object[] overload which is expensive.
+ protected unsafe void WriteEvent(int eventId, int arg1, short arg2, long arg3)
+ {
+ if (IsEnabled())
+ {
+ EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
+ descrs[0] = new EventData { DataPointer = (IntPtr)(&arg1), Size = 4 };
+ descrs[1] = new EventData { DataPointer = (IntPtr)(&arg2), Size = 2 };
+ descrs[2] = new EventData { DataPointer = (IntPtr)(&arg3), Size = 8 };
+ WriteEventCore(eventId, 3, descrs);
+ }
+ }
+ }
+
+ public sealed class OptimizedEventSource : UtilBaseEventSource
+ {
+ public static OptimizedEventSource Log = new();
+
+ public static class Keywords
+ {
+ public const EventKeywords Kwd1 = (EventKeywords)1;
+ }
+
+ [Event(1, Keywords = Keywords.Kwd1, Level = EventLevel.Informational, Message = "LogElements called {0}/{1}/{2}.")]
+ public void LogElements(int n, short sh, long l) => WriteEvent(1, n, sh, l); // uses the overload we added!
+ }
+ //
+
+ //
+ public class ComplexComponent : IDisposable
+ {
+ internal static Dictionary _internalState = new();
+
+ private string _name;
+
+ public ComplexComponent(string name)
+ {
+ _name = name ?? throw new ArgumentNullException(nameof(name));
+ ComplexSource.Log.NewComponent(_name);
+ }
+
+ public void SetState(string key, string value)
+ {
+ lock (_internalState)
+ {
+ _internalState[key] = value;
+ ComplexSource.Log.SetState(_name, key, value);
+ }
+ }
+
+ private void ExpensiveWork1() => System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(250));
+ private void ExpensiveWork2() => System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(250));
+ private void ExpensiveWork3() => System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(250));
+ private void ExpensiveWork4() => System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(250));
+
+ public void DoWork()
+ {
+ ComplexSource.Log.ExpensiveWorkStart(_name);
+
+ ExpensiveWork1();
+ ExpensiveWork2();
+ ExpensiveWork3();
+ ExpensiveWork4();
+
+ ComplexSource.Log.ExpensiveWorkStop(_name);
+ }
+
+ public void Dispose()
+ {
+ ComplexSource.Log.ComponentDisposed(_name);
+ }
+ }
+
+ internal sealed class ComplexSource : EventSource
+ {
+ public static ComplexSource Log = new();
+
+ public static class Keywords
+ {
+ public const EventKeywords ComponentLifespan = (EventKeywords)1;
+ public const EventKeywords StateChanges = (EventKeywords)(1 << 1);
+ public const EventKeywords Performance = (EventKeywords)(1 << 2);
+ public const EventKeywords DumpState = (EventKeywords)(1 << 3);
+ // a utility keyword for a common combination of keywords users might enable
+ public const EventKeywords StateTracking = ComponentLifespan & StateChanges & DumpState;
+ }
+
+ protected override void OnEventCommand(EventCommandEventArgs args)
+ {
+ base.OnEventCommand(args);
+
+ if (args.Command == EventCommand.Enable)
+ {
+ DumpComponentState();
+ }
+ }
+
+ [Event(1, Keywords = Keywords.ComponentLifespan, Message = "New component with name '{0}'.")]
+ public void NewComponent(string name) => WriteEvent(1, name);
+
+ [Event(2, Keywords = Keywords.ComponentLifespan, Message = "Component with name '{0}' disposed.")]
+ public void ComponentDisposed(string name) => WriteEvent(2, name);
+
+ [Event(3, Keywords = Keywords.StateChanges)]
+ public void SetState(string name, string key, string value) => WriteEvent(3, name, key, value);
+
+ [Event(4, Keywords = Keywords.Performance)]
+ public void ExpensiveWorkStart(string name) => WriteEvent(4, name);
+
+ [Event(5, Keywords = Keywords.Performance)]
+ public void ExpensiveWorkStop(string name) => WriteEvent(5, name);
+
+ [Event(6, Keywords = Keywords.DumpState)]
+ public void ComponentState(string key, string value) => WriteEvent(6, key, value);
+
+ [NonEvent]
+ public void DumpComponentState()
+ {
+ if (IsEnabled(EventLevel.Informational, Keywords.DumpState))
+ {
+ lock (ComplexComponent._internalState)
+ {
+ foreach (var (key, value) in ComplexComponent._internalState)
+ ComponentState(key, value);
+ }
+ }
+ }
+ }
+ //
+
+ //
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine($"PID: {System.Diagnostics.Process.GetCurrentProcess().Id}");
+
+ long i = 0;
+ while (true)
+ {
+ using ComplexComponent c1 = new($"COMPONENT_{i++}");
+ using ComplexComponent c2 = new($"COMPONENT_{i++}");
+ using ComplexComponent c3 = new($"COMPONENT_{i++}");
+ using ComplexComponent c4 = new($"COMPONENT_{i++}");
+
+ c1.SetState("key1", "value1");
+ c2.SetState("key2", "value2");
+ c3.SetState("key3", "value3");
+ c4.SetState("key4", "value4");
+
+ c1.DoWork();
+ c2.DoWork();
+ c3.DoWork();
+ c4.DoWork();
+ }
+ }
+ }
+ //
+}
+//
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/Project.csproj b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/Project.csproj
new file mode 100644
index 00000000000..2da0e2c4887
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/Project.csproj
@@ -0,0 +1,12 @@
+
+
+
+ Library
+ net10.0
+
+
+
+
+
+
+
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.cs
new file mode 100644
index 00000000000..a729d165f2b
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.cs
@@ -0,0 +1,370 @@
+// Notice that the sample is conditionally compiled for Everett vs.
+// Whidbey builds. Whidbey introduced new APIs that are not available
+// in Everett. Snippet IDs do not overlap between Whidbey and Everett;
+// Snippet #1 is Everett, Snippet #2 and #3 are Whidbey.
+
+#if (BELOW_WHIDBEY_BUILD)
+
+//
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+public class App
+{
+
+ private static PerformanceCounter PC;
+ private static PerformanceCounter BPC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ SetupCategory();
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+
+
+
+ private static bool SetupCategory()
+ {
+
+ if ( !PerformanceCounterCategory.Exists("AverageTimer32SampleCategory") )
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData averageTimer32 = new CounterCreationData();
+ averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
+ averageTimer32.CounterName = "AverageTimer32Sample";
+ CCDC.Add(averageTimer32);
+
+ // Add the base counter.
+ CounterCreationData averageTimer32Base = new CounterCreationData();
+ averageTimer32Base.CounterType = PerformanceCounterType.AverageBase;
+ averageTimer32Base.CounterName = "AverageTimer32SampleBase";
+ CCDC.Add(averageTimer32Base);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("AverageTimer32SampleCategory",
+ "Demonstrates usage of the AverageTimer32 performance counter type",
+ CCDC);
+
+ return(true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - " + "AverageTimer32SampleCategory");
+ return(false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counters.
+ PC = new PerformanceCounter("AverageTimer32SampleCategory",
+ "AverageTimer32Sample",
+ false);
+
+ BPC = new PerformanceCounter("AverageTimer32SampleCategory",
+ "AverageTimer32SampleBase",
+ false);
+
+ PC.RawValue = 0;
+ BPC.RawValue = 0;
+ }
+
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ long perfTime = 0;
+ Random r = new Random( DateTime.Now.Millisecond );
+
+ // Loop for the samples.
+ for (int i = 0; i < 10; i++) {
+
+ QueryPerformanceCounter(out perfTime);
+ PC.RawValue = perfTime;
+
+ BPC.IncrementBy(10);
+
+ System.Threading.Thread.Sleep(1000);
+ Console.WriteLine("Next value = " + PC.NextValue().ToString());
+ samplesList.Add(PC.NextSample());
+ }
+
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for(int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample( (CounterSample)samplesList[i] );
+ OutputSample( (CounterSample)samplesList[i+1] );
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSample.Calculate((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i+1]) );
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i+1]) );
+
+ }
+ }
+
+
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ // PERF_AVERAGE_TIMER
+ // Description - This counter type measures the time it takes, on
+ // average, to complete a process or operation. Counters of this
+ // type display a ratio of the total elapsed time of the sample
+ // interval to the number of processes or operations completed
+ // during that time. This counter type measures time in ticks
+ // of the system clock. The F variable represents the number of
+ // ticks per second. The value of F is factored into the equation
+ // so that the result can be displayed in seconds.
+ //
+ // Generic type - Average
+ //
+ // Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
+ // represents the number of ticks counted during the last
+ // sample interval, F represents the frequency of the ticks,
+ // and the denominator (D) represents the number of operations
+ // completed during the last sample interval.
+ //
+ // Average - ((Nx - N0) / F) / (Dx - D0)
+ //
+ // Example - PhysicalDisk\ Avg. Disk sec/Transfer
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Int64 n1 = s1.RawValue;
+ Int64 n0 = s0.RawValue;
+ ulong f = (ulong)s1.SystemFrequency;
+ Int64 d1 = s1.BaseValue;
+ Int64 d0 = s0.BaseValue;
+
+ double numerator = (double)(n1 - n0);
+ double denominator = (double)(d1 - d0);
+ Single counterValue = (Single)(( numerator / f ) / denominator);
+ return(counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+
+
+ [DllImport("Kernel32.dll")]
+ public static extern bool QueryPerformanceCounter(out long value);
+
+}
+
+//
+#else
+// Build sample for Whidbey or higher.
+
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Runtime.Versioning;
+
+[SupportedOSPlatform("Windows")]
+public class App2
+{
+ private static PerformanceCounter PC;
+ private static PerformanceCounter BPC;
+
+ private const String categoryName = "AverageTimer32SampleCategory";
+ private const String counterName = "AverageTimer32Sample";
+ private const String baseCounterName = "AverageTimer32SampleBase";
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Performance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+ if (!PerformanceCounterCategory.Exists(categoryName))
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData averageTimer32 = new CounterCreationData();
+ averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
+ averageTimer32.CounterName = counterName;
+ CCDC.Add(averageTimer32);
+
+ // Add the base counter.
+ CounterCreationData averageTimer32Base = new CounterCreationData();
+ averageTimer32Base.CounterType = PerformanceCounterType.AverageBase;
+ averageTimer32Base.CounterName = baseCounterName;
+ CCDC.Add(averageTimer32Base);
+
+ // Create the category.
+ PerformanceCounterCategory.Create(categoryName,
+ "Demonstrates usage of the AverageTimer32 performance counter type",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+
+ Console.WriteLine("Category created - " + categoryName);
+
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - " + categoryName);
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counters.
+ PC = new PerformanceCounter(categoryName,
+ counterName,
+ false);
+
+ BPC = new PerformanceCounter(categoryName,
+ baseCounterName,
+ false);
+
+ PC.RawValue = 0;
+ BPC.RawValue = 0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ Random r = new Random(DateTime.Now.Millisecond);
+
+ // Loop for the samples.
+ for (int i = 0; i < 10; i++)
+ {
+
+ PC.RawValue = Stopwatch.GetTimestamp();
+
+ BPC.IncrementBy(10);
+
+ System.Threading.Thread.Sleep(1000);
+
+ Console.WriteLine("Next value = " + PC.NextValue().ToString());
+ samplesList.Add(PC.NextSample());
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+ OutputSample((CounterSample)samplesList[i + 1]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSample.Calculate((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ // PERF_AVERAGE_TIMER
+ // Description - This counter type measures the time it takes, on
+ // average, to complete a process or operation. Counters of this
+ // type display a ratio of the total elapsed time of the sample
+ // interval to the number of processes or operations completed
+ // during that time. This counter type measures time in ticks
+ // of the system clock. The F variable represents the number of
+ // ticks per second. The value of F is factored into the equation
+ // so that the result can be displayed in seconds.
+ //
+ // Generic type - Average
+ //
+ // Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
+ // represents the number of ticks counted during the last
+ // sample interval, F represents the frequency of the ticks,
+ // and the denominator (D) represents the number of operations
+ // completed during the last sample interval.
+ //
+ // Average - ((Nx - N0) / F) / (Dx - D0)
+ //
+ // Example - PhysicalDisk\ Avg. Disk sec/Transfer
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Int64 n1 = s1.RawValue;
+ Int64 n0 = s0.RawValue;
+ ulong f = (ulong)s1.SystemFrequency;
+ Int64 d1 = s1.BaseValue;
+ Int64 d0 = s0.BaseValue;
+
+ double numerator = (double)(n1 - n0);
+ double denominator = (double)(d1 - d0);
+ Single counterValue = (Single)((numerator / f) / denominator);
+ return (counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+
+//
+
+#endif
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.cs
new file mode 100644
index 00000000000..18eee683b86
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.cs
@@ -0,0 +1,137 @@
+//
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Diagnostics;
+
+public class NumberOfItems64
+{
+
+ private static PerformanceCounter PC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Performance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+ if ( !PerformanceCounterCategory.Exists("NumberOfItems32SampleCategory") )
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData NOI64 = new CounterCreationData();
+ NOI64.CounterType = PerformanceCounterType.NumberOfItems64;
+ NOI64.CounterName = "NumberOfItems32Sample";
+ CCDC.Add(NOI64);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("NumberOfItems32SampleCategory",
+ "Demonstrates usage of the NumberOfItems32 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+
+ return(true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - NumberOfItems32SampleCategory");
+ return(false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counter.
+ PC = new PerformanceCounter("NumberOfItems32SampleCategory",
+ "NumberOfItems32Sample",
+ false);
+
+ PC.RawValue=0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ Random r = new Random( DateTime.Now.Millisecond );
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+
+ int value = r.Next(1, 10);
+ Console.Write(j + " = " + value);
+
+ PC.IncrementBy(value);
+
+ if ((j % 10) == 9)
+ {
+ OutputSample(PC.NextSample());
+ samplesList.Add( PC.NextSample() );
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for(int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample( (CounterSample)samplesList[i] );
+ OutputSample( (CounterSample)samplesList[i+1] );
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i+1]) );
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i+1]) );
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Single counterValue = s1.RawValue;
+ return(counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("\r\n+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+//
\ No newline at end of file
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.cs
new file mode 100644
index 00000000000..ca73e6be7ff
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.cs
@@ -0,0 +1,134 @@
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Runtime.Versioning;
+
+[SupportedOSPlatform("Windows")]
+public class NumberOfItems64_1
+{
+ private static PerformanceCounter PC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Perfomance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+ if (!PerformanceCounterCategory.Exists("NumberOfItems64SampleCategory"))
+ {
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData NOI64 = new CounterCreationData();
+ NOI64.CounterType = PerformanceCounterType.NumberOfItems64;
+ NOI64.CounterName = "NumberOfItems64Sample";
+ CCDC.Add(NOI64);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("NumberOfItems64SampleCategory",
+ "Demonstrates usage of the NumberOfItems64 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - NumberOfItems64SampleCategory");
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counters.
+ PC = new PerformanceCounter("NumberOfItems64SampleCategory",
+ "NumberOfItems64Sample",
+ false);
+
+ PC.RawValue = 0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+ Random r = new Random(DateTime.Now.Millisecond);
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+
+ int value = r.Next(1, 10);
+ Console.Write(j + " = " + value);
+
+ PC.IncrementBy(value);
+
+ if ((j % 10) == 9)
+ {
+ OutputSample(PC.NextSample());
+ samplesList.Add(PC.NextSample());
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+ OutputSample((CounterSample)samplesList[i + 1]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Single counterValue = s1.RawValue;
+ return (counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("\r\n+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+//
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/program.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/program.cs
new file mode 100644
index 00000000000..6cdc59d744b
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/program.cs
@@ -0,0 +1,155 @@
+//
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Diagnostics;
+
+// Provides a SampleFraction counter to measure the percentage of the user processor
+// time for this process to total processor time for the process.
+public class App
+{
+
+ private static PerformanceCounter perfCounter;
+ private static PerformanceCounter basePerfCounter;
+ private static Process thisProcess = Process.GetCurrentProcess();
+
+ public static void Main()
+ {
+
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Performance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+ if (!PerformanceCounterCategory.Exists("SampleFractionCategory"))
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData sampleFraction = new CounterCreationData();
+ sampleFraction.CounterType = PerformanceCounterType.SampleFraction;
+ sampleFraction.CounterName = "SampleFractionSample";
+ CCDC.Add(sampleFraction);
+
+ // Add the base counter.
+ CounterCreationData sampleFractionBase = new CounterCreationData();
+ sampleFractionBase.CounterType = PerformanceCounterType.SampleBase;
+ sampleFractionBase.CounterName = "SampleFractionSampleBase";
+ CCDC.Add(sampleFractionBase);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("SampleFractionCategory",
+ "Demonstrates usage of the SampleFraction performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - SampleFractionCategory");
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counters.
+
+ perfCounter = new PerformanceCounter("SampleFractionCategory",
+ "SampleFractionSample",
+ false);
+
+ basePerfCounter = new PerformanceCounter("SampleFractionCategory",
+ "SampleFractionSampleBase",
+ false);
+
+ perfCounter.RawValue = thisProcess.UserProcessorTime.Ticks;
+ basePerfCounter.RawValue = thisProcess.TotalProcessorTime.Ticks;
+ }
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+
+ perfCounter.IncrementBy(thisProcess.UserProcessorTime.Ticks);
+
+ basePerfCounter.IncrementBy(thisProcess.TotalProcessorTime.Ticks);
+
+ if ((j % 10) == 9)
+ {
+ OutputSample(perfCounter.NextSample());
+ samplesList.Add(perfCounter.NextSample());
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+ OutputSample((CounterSample)samplesList[i + 1]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ // Description - This counter type provides A percentage counter that shows the
+ // average ratio of user proccessor time to total processor time during the last
+ // two sample intervals.
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Single numerator = (Single)s1.RawValue - (Single)s0.RawValue;
+ Single denomenator = (Single)s1.BaseValue - (Single)s0.BaseValue;
+ Single counterValue = 100 * (numerator / denomenator);
+ return (counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("\r\n+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+//
\ No newline at end of file
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.cs
new file mode 100644
index 00000000000..0ccd952350c
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.cs
@@ -0,0 +1,159 @@
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Runtime.Versioning;
+
+[SupportedOSPlatform("Windows")]
+public class App3
+{
+ private static PerformanceCounter PC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Perfomance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+ if (!PerformanceCounterCategory.Exists("RateOfCountsPerSecond32SampleCategory"))
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData rateOfCounts32 = new CounterCreationData();
+ rateOfCounts32.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
+ rateOfCounts32.CounterName = "RateOfCountsPerSecond32Sample";
+ CCDC.Add(rateOfCounts32);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("RateOfCountsPerSecond32SampleCategory",
+ "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - RateOfCountsPerSecond32SampleCategory");
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counter.
+ PC = new PerformanceCounter("RateOfCountsPerSecond32SampleCategory",
+ "RateOfCountsPerSecond32Sample",
+ false);
+
+ PC.RawValue = 0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ Random r = new Random(DateTime.Now.Millisecond);
+
+ // Initialize the performance counter.
+ PC.NextSample();
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+
+ int value = r.Next(1, 10);
+ PC.IncrementBy(value);
+ Console.Write(j + " = " + value);
+
+ if ((j % 10) == 9)
+ {
+ Console.WriteLine("; NextValue() = " + PC.NextValue().ToString());
+ OutputSample(PC.NextSample());
+ samplesList.Add(PC.NextSample());
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+ OutputSample((CounterSample)samplesList[i + 1]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ // PERF_COUNTER_COUNTER
+ // Description - This counter type shows the average number of operations completed
+ // during each second of the sample interval. Counters of this type
+ // measure time in ticks of the system clock. The F variable represents
+ // the number of ticks per second. The value of F is factored into the
+ // equation so that the result can be displayed in seconds.
+ //
+ // Generic type - Difference
+ //
+ // Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
+ // of operations performed during the last sample interval, the denominator
+ // (D) represents the number of ticks elapsed during the last sample
+ // interval, and F is the frequency of the ticks.
+ //
+ // Average - (Nx - N0) / ((Dx - D0) / F)
+ //
+ // Example - System\ File Read Operations/sec
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Single numerator = (Single)(s1.RawValue - s0.RawValue);
+ Single denomenator = (Single)(s1.TimeStamp - s0.TimeStamp) / (Single)s1.SystemFrequency;
+ Single counterValue = numerator / denomenator;
+ return (counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("\r\n+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+
+//
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.cs
new file mode 100644
index 00000000000..8e3c492d862
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.cs
@@ -0,0 +1,159 @@
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Runtime.Versioning;
+
+[SupportedOSPlatform("Windows")]
+public class App4
+{
+ private static PerformanceCounter PC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Perfomance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the category.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+
+ if (!PerformanceCounterCategory.Exists("RateOfCountsPerSecond64SampleCategory"))
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData rateOfCounts64 = new CounterCreationData();
+ rateOfCounts64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
+ rateOfCounts64.CounterName = "RateOfCountsPerSecond64Sample";
+ CCDC.Add(rateOfCounts64);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("RateOfCountsPerSecond64SampleCategory",
+ "Demonstrates usage of the RateOfCountsPerSecond64 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - RateOfCountsPerSecond64SampleCategory");
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counter.
+ PC = new PerformanceCounter("RateOfCountsPerSecond64SampleCategory",
+ "RateOfCountsPerSecond64Sample",
+ false);
+
+ PC.RawValue = 0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ Random r = new Random(DateTime.Now.Millisecond);
+
+ // Initialize the performance counter.
+ PC.NextSample();
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+
+ int value = r.Next(1, 10);
+ PC.IncrementBy(value);
+ Console.Write(j + " = " + value);
+
+ if ((j % 10) == 9)
+ {
+ Console.WriteLine("; NextValue() = " + PC.NextValue().ToString());
+ OutputSample(PC.NextSample());
+ samplesList.Add(PC.NextSample());
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < (samplesList.Count - 1); i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+ OutputSample((CounterSample)samplesList[i + 1]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i],
+ (CounterSample)samplesList[i + 1]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ // PERF_COUNTER_COUNTER
+ // Description - This counter type shows the average number of operations completed
+ // during each second of the sample interval. Counters of this type
+ // measure time in ticks of the system clock. The F variable represents
+ // the number of ticks per second. The value of F is factored into the
+ // equation so that the result can be displayed in seconds.
+ //
+ // Generic type - Difference
+ //
+ // Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
+ // of operations performed during the last sample interval, the denominator
+ // (D) represents the number of ticks elapsed during the last sample
+ // interval, and F is the frequency of the ticks.
+ //
+ // Average - (Nx - N0) / ((Dx - D0) / F)
+ //
+ // Example - System\ File Read Operations/sec
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
+ {
+ Single numerator = (Single)(s1.RawValue - s0.RawValue);
+ Single denomenator = (Single)(s1.TimeStamp - s0.TimeStamp) / (Single)s1.SystemFrequency;
+ Single counterValue = numerator / denomenator;
+ return (counterValue);
+ }
+
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("\r\n+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+
+//
diff --git a/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.cs b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.cs
new file mode 100644
index 00000000000..008ab43884c
--- /dev/null
+++ b/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.cs
@@ -0,0 +1,172 @@
+//
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Runtime.Versioning;
+
+[SupportedOSPlatform("Windows")]
+public class App5
+{
+ private static PerformanceCounter PC;
+ private static PerformanceCounter BPC;
+
+ public static void Main()
+ {
+ ArrayList samplesList = new ArrayList();
+
+ // If the category does not exist, create the category and exit.
+ // Performance counters should not be created and immediately used.
+ // There is a latency time to enable the counters, they should be created
+ // prior to executing the application that uses the counters.
+ // Execute this sample a second time to use the counters.
+ if (SetupCategory())
+ return;
+ CreateCounters();
+ CollectSamples(samplesList);
+ CalculateResults(samplesList);
+ }
+
+ private static bool SetupCategory()
+ {
+
+ if (!PerformanceCounterCategory.Exists("RawFractionSampleCategory"))
+ {
+
+ CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
+
+ // Add the counter.
+ CounterCreationData rf = new CounterCreationData();
+ rf.CounterType = PerformanceCounterType.RawFraction;
+ rf.CounterName = "RawFractionSample";
+ CCDC.Add(rf);
+
+ // Add the base counter.
+ CounterCreationData rfBase = new CounterCreationData();
+ rfBase.CounterType = PerformanceCounterType.RawBase;
+ rfBase.CounterName = "RawFractionSampleBase";
+ CCDC.Add(rfBase);
+
+ // Create the category.
+ PerformanceCounterCategory.Create("RawFractionSampleCategory",
+ "Demonstrates usage of the RawFraction performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC);
+
+ return (true);
+ }
+ else
+ {
+ Console.WriteLine("Category exists - RawFractionSampleCategory");
+ return (false);
+ }
+ }
+
+ private static void CreateCounters()
+ {
+ // Create the counters.
+ PC = new PerformanceCounter("RawFractionSampleCategory",
+ "RawFractionSample",
+ false);
+
+ BPC = new PerformanceCounter("RawFractionSampleCategory",
+ "RawFractionSampleBase",
+ false);
+
+ PC.RawValue = 0;
+ BPC.RawValue = 0;
+ }
+
+ private static void CollectSamples(ArrayList samplesList)
+ {
+
+ Random r = new Random(DateTime.Now.Millisecond);
+
+ // Initialize the performance counter.
+ PC.NextSample();
+
+ // Loop for the samples.
+ for (int j = 0; j < 100; j++)
+ {
+ int value = r.Next(1, 10);
+ Console.Write(j + " = " + value);
+
+ // Increment the base every time, because the counter measures the number
+ // of high hits (raw fraction value) against all the hits (base value).
+ BPC.Increment();
+
+ // Get the % of samples that are 9 or 10 out of all the samples taken.
+ if (value >= 9)
+ PC.Increment();
+
+ // Copy out the next value every ten times around the loop.
+ if ((j % 10) == 9)
+ {
+ Console.WriteLine("; NextValue() = " + PC.NextValue().ToString());
+ OutputSample(PC.NextSample());
+ samplesList.Add(PC.NextSample());
+ }
+ else
+ {
+ Console.WriteLine();
+ }
+
+ System.Threading.Thread.Sleep(50);
+ }
+ }
+
+ private static void CalculateResults(ArrayList samplesList)
+ {
+ for (int i = 0; i < samplesList.Count; i++)
+ {
+ // Output the sample.
+ OutputSample((CounterSample)samplesList[i]);
+
+ // Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " +
+ CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i]));
+
+ // Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " +
+ MyComputeCounterValue((CounterSample)samplesList[i]));
+ }
+ }
+
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ // Formula from MSDN -
+ // Description - This counter type shows the ratio of a subset to its set as a percentage.
+ // For example, it compares the number of bytes in use on a disk to the
+ // total number of bytes on the disk. Counters of this type display the
+ // current percentage only, not an average over time.
+ //
+ // Generic type - Instantaneous, Percentage
+ // Formula - (N0 / D0), where D represents a measured attribute and N represents one
+ // component of that attribute.
+ //
+ // Average - SUM (N / D) /x
+ // Example - Paging File\% Usage Peak
+ //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ private static Single MyComputeCounterValue(CounterSample rfSample)
+ {
+ Single numerator = (Single)rfSample.RawValue;
+ Single denomenator = (Single)rfSample.BaseValue;
+ Single counterValue = (numerator / denomenator) * 100;
+ return (counterValue);
+ }
+
+ // Output information about the counter sample.
+ private static void OutputSample(CounterSample s)
+ {
+ Console.WriteLine("+++++++++++");
+ Console.WriteLine("Sample values - \r\n");
+ Console.WriteLine(" BaseValue = " + s.BaseValue);
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
+ Console.WriteLine(" CounterType = " + s.CounterType);
+ Console.WriteLine(" RawValue = " + s.RawValue);
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp);
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
+ Console.WriteLine("++++++++++++++++++++++");
+ }
+}
+
+//
diff --git a/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/Project.vbproj b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/Project.vbproj
new file mode 100644
index 00000000000..874c98f3477
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/Project.vbproj
@@ -0,0 +1,8 @@
+
+
+
+ Library
+ net10.0
+
+
+
diff --git a/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program.vb b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program.vb
new file mode 100644
index 00000000000..95de28d88a3
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program.vb
@@ -0,0 +1,36 @@
+'
+Imports System.Diagnostics.Tracing
+
+'
+Class MyCompanyEventSource
+ Inherits EventSource
+ Public Shared Log As New MyCompanyEventSource()
+
+ Public Sub Startup()
+ WriteEvent(1)
+ End Sub
+
+ Public Sub OpenFileStart(ByVal fileName As String)
+ WriteEvent(2, fileName)
+ End Sub
+
+ Public Sub OpenFileStop()
+ WriteEvent(3)
+ End Sub
+End Class
+'
+
+'
+Class Program
+
+ Shared Sub Main(ByVal args() As String)
+ MyCompanyEventSource.Log.Startup()
+ ' ...
+ MyCompanyEventSource.Log.OpenFileStart("SomeFile")
+ ' ...
+ MyCompanyEventSource.Log.OpenFileStop()
+
+ End Sub
+End Class
+'
+'
\ No newline at end of file
diff --git a/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program1.vb b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program1.vb
new file mode 100644
index 00000000000..41046ab3778
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program1.vb
@@ -0,0 +1,118 @@
+'
+Imports System.Diagnostics.Tracing
+
+Enum MyColor
+ Red
+ Yellow
+ Blue
+End Enum 'MyColor
+
+Class MyCompanyEventSource1
+ Inherits EventSource
+
+ '
+ '
+ Public Class Keywords
+ Public Const Page As EventKeywords = CType(1, EventKeywords)
+ Public Const DataBase As EventKeywords = CType(2, EventKeywords)
+ Public Const Diagnostic As EventKeywords = CType(4, EventKeywords)
+ Public Const Perf As EventKeywords = CType(8, EventKeywords)
+ End Class
+ '
+
+ '
+ Public Class Tasks
+ Public Const Page As EventTask = CType(1, EventTask)
+ Public Const DBQuery As EventTask = CType(1, EventTask)
+ End Class
+ '
+ '
+
+ '
+ <[Event](1, Message:="Application Failure: {0}", Level:=EventLevel.Error, Keywords:=Keywords.Diagnostic)>
+ Public Sub Failure(ByVal message As String)
+ WriteEvent(1, message)
+ End Sub
+ '
+
+ '
+ <[Event](2, Message:="Starting up.", Keywords:=Keywords.Perf, Level:=EventLevel.Informational)>
+ Public Sub Startup()
+ WriteEvent(2)
+ End Sub
+ '
+
+ '
+ <[Event](3, Message:="loading page {1} activityID={0}", Opcode:=EventOpcode.Start, Task:=Tasks.Page, Keywords:=Keywords.Page, Level:=EventLevel.Informational)>
+ Public Sub PageStart(ByVal ID As Integer, ByVal url As String)
+ If IsEnabled() Then
+ WriteEvent(3, ID, url)
+ End If
+ End Sub
+ '
+
+ '
+ <[Event](4, Opcode:=EventOpcode.Stop, Task:=Tasks.Page, Keywords:=Keywords.Page, Level:=EventLevel.Informational)>
+ Public Sub PageStop(ByVal ID As Integer)
+ If IsEnabled() Then
+ WriteEvent(4, ID)
+ End If
+ End Sub
+ '
+
+ '
+ <[Event](5, Opcode:=EventOpcode.Start, Task:=Tasks.DBQuery, Keywords:=Keywords.DataBase, Level:=EventLevel.Informational)>
+ Public Sub DBQueryStart(ByVal sqlQuery As String)
+ WriteEvent(5, sqlQuery)
+ End Sub
+ '
+
+ '
+ <[Event](6, Opcode:=EventOpcode.Stop, Task:=Tasks.DBQuery, Keywords:=Keywords.DataBase, Level:=EventLevel.Informational)>
+ Public Sub DBQueryStop()
+ WriteEvent(6)
+ End Sub
+ '
+
+ '
+ <[Event](7, Level:=EventLevel.Verbose, Keywords:=Keywords.DataBase)>
+ Public Sub Mark(ByVal ID As Integer)
+ If IsEnabled() Then
+ WriteEvent(7, ID)
+ End If
+ End Sub
+ '
+
+ '
+ <[Event](8)>
+ Public Sub LogColor(ByVal color As MyColor)
+ WriteEvent(8, Fix(color))
+ End Sub
+ '
+ Public Shared Log As New MyCompanyEventSource1()
+End Class
+
+Class Program1
+
+ Shared Sub Main(ByVal args() As String)
+ '
+ MyCompanyEventSource1.Log.Startup()
+ Console.WriteLine("Starting up")
+ MyCompanyEventSource1.Log.DBQueryStart("Select * from MYTable")
+ Dim url As String = "http:'localhost"
+ Dim i As Integer
+ For i = 0 To 9
+ MyCompanyEventSource1.Log.PageStart(i, url)
+ MyCompanyEventSource1.Log.Mark(i)
+ MyCompanyEventSource1.Log.PageStop(i)
+ Next i
+ MyCompanyEventSource1.Log.DBQueryStop()
+ MyCompanyEventSource1.Log.LogColor(MyColor.Blue)
+
+ MyCompanyEventSource1.Log.Failure("This is a failure 1")
+ MyCompanyEventSource1.Log.Failure("This is a failure 2")
+ MyCompanyEventSource1.Log.Failure("This is a failure 3")
+ '
+ End Sub
+End Class
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/Project.vbproj b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/Project.vbproj
new file mode 100644
index 00000000000..2da0e2c4887
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/Project.vbproj
@@ -0,0 +1,12 @@
+
+
+
+ Library
+ net10.0
+
+
+
+
+
+
+
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagecount32.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagecount32.vb
new file mode 100644
index 00000000000..067203ae7ec
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagecount32.vb
@@ -0,0 +1,149 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class App1
+
+ Private Shared avgCounter64Sample As PerformanceCounter
+ Private Shared avgCounter64SampleBase As PerformanceCounter
+
+ Public Shared Sub Main()
+
+ Dim samplesList As New ArrayList()
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the App1lication that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+
+ End Sub
+
+ Private Shared Function SetupCategory() As Boolean
+ If Not PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") Then
+
+ Dim counterDataCollection As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim averageCount64 As New CounterCreationData()
+ averageCount64.CounterType = PerformanceCounterType.AverageCount64
+ averageCount64.CounterName = "AverageCounter64Sample"
+ counterDataCollection.Add(averageCount64)
+
+ ' Add the base counter.
+ Dim averageCount64Base As New CounterCreationData()
+ averageCount64Base.CounterType = PerformanceCounterType.AverageBase
+ averageCount64Base.CounterName = "AverageCounter64SampleBase"
+ counterDataCollection.Add(averageCount64Base)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
+ "Demonstrates usage of the AverageCounter64 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, counterDataCollection)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - AverageCounter64SampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+
+ '
+ avgCounter64Sample = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64Sample", False)
+ '
+
+ avgCounter64SampleBase = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64SampleBase", False)
+
+ avgCounter64Sample.RawValue = 0
+ avgCounter64SampleBase.RawValue = 0
+ End Sub
+
+ '
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ Dim value As Integer = r.Next(1, 10)
+ Console.Write(j.ToString() + " = " + value.ToString())
+
+ avgCounter64Sample.IncrementBy(value)
+
+ avgCounter64SampleBase.Increment()
+
+ If j Mod 10 = 9 Then
+ OutputSample(avgCounter64Sample.NextSample())
+ samplesList.Add(avgCounter64Sample.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+ '
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+ Next i
+ End Sub
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ ' Description - This counter type shows how many items are processed, on average,
+ ' during an operation. Counters of this type display a ratio of the items
+ ' processed (such as bytes sent) to the number of operations completed. The
+ ' ratio is calculated by comparing the number of items processed during the
+ ' last interval to the number of operations completed during the last interval.
+ ' Generic type - Average
+ ' Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number
+ ' of items processed during the last sample interval and the denominator (D)
+ ' represents the number of operations completed during the last two sample
+ ' intervals.
+ ' Average (Nx - N0) / (Dx - D0)
+ ' Example PhysicalDisk\ Avg. Disk Bytes/Transfer
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim numerator As [Single] = CType(s1.RawValue, [Single]) - CType(s0.RawValue, [Single])
+ Dim denomenator As [Single] = CType(s1.BaseValue, [Single]) - CType(s0.BaseValue, [Single])
+ Dim counterValue As [Single] = numerator / denomenator
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.vb
new file mode 100644
index 00000000000..a415b8951c5
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.vb
@@ -0,0 +1,392 @@
+' Notice that the sample is conditionally compiled for Everett vs.
+' Whidbey builds. Whidbey introduced new APIs that are not available
+' in Everett. Snippet IDs do not overlap between Whidbey and Everett;
+' Snippet #1 is Everett, Snippet #2 and #3 are Whidbey.
+
+#If BELOW_WHIDBEY_BUILD Then
+
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.InteropServices
+
+Public Class App
+
+ Private Shared PC As PerformanceCounter
+ Private Shared BPC As PerformanceCounter
+
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the application that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+
+ If Not PerformanceCounterCategory.Exists("AverageTimer32SampleCategory") Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim averageTimer32 As New CounterCreationData()
+ averageTimer32.CounterType = PerformanceCounterType.AverageTimer32
+ averageTimer32.CounterName = "AverageTimer32Sample"
+ CCDC.Add(averageTimer32)
+
+ ' Add the base counter.
+ Dim averageTimer32Base As New CounterCreationData()
+ averageTimer32Base.CounterType = PerformanceCounterType.AverageBase
+ averageTimer32Base.CounterName = "AverageTimer32SampleBase"
+ CCDC.Add(averageTimer32Base)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create( _
+ "AverageTimer32SampleCategory", _
+ "Demonstrates usage of the AverageTimer32 performance counter type", _
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Return True
+ Else
+ Console.WriteLine(("Category exists - " + _
+ "AverageTimer32SampleCategory"))
+ Return False
+ End If
+ End Function
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+ PC = New PerformanceCounter("AverageTimer32SampleCategory", _
+ "AverageTimer32Sample", False)
+
+ BPC = New PerformanceCounter("AverageTimer32SampleCategory", _
+ "AverageTimer32SampleBase", False)
+
+ PC.RawValue = 0
+ BPC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(samplesList As ArrayList)
+
+ Dim perfTime As Long = 0
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Loop for the samples.
+ Dim i As Integer
+ For i = 0 To 9
+
+ QueryPerformanceCounter(perfTime)
+ PC.RawValue = perfTime
+
+ BPC.IncrementBy(10)
+
+ System.Threading.Thread.Sleep(1000)
+ Console.WriteLine(("Next value = " + PC.NextValue().ToString()))
+ samplesList.Add(PC.NextSample())
+ Next i
+ End Sub
+
+
+ Private Shared Sub CalculateResults(samplesList As ArrayList)
+ Dim i As Integer
+ Dim sample1 As CounterSample
+ Dim sample2 As CounterSample
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ sample1 = CType(samplesList(i), CounterSample)
+ sample2 = CType(samplesList(i+1), CounterSample)
+ OutputSample(sample1)
+ OutputSample(sample2)
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine((".NET computed counter value = " _
+ + CounterSample.Calculate(sample1, sample2).ToString()))
+
+ ' Calculate the counter value manually.
+ Console.WriteLine(("My computed counter value = " _
+ + MyComputeCounterValue(sample1, sample2).ToString()))
+
+ Next i
+ End Sub
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ ' PERF_AVERAGE_TIMER
+ ' Description - This counter type measures the time it takes, on
+ ' average, to complete a process or operation. Counters of this
+ ' type display a ratio of the total elapsed time of the sample
+ ' interval to the number of processes or operations completed
+ ' during that time. This counter type measures time in ticks
+ ' of the system clock. The F variable represents the number of
+ ' ticks per second. The value of F is factored into the equation
+ ' so that the result can be displayed in seconds.
+ '
+ ' Generic type - Average
+ '
+ ' Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
+ ' represents the number of ticks counted during the last
+ ' sample interval, F represents the frequency of the ticks,
+ ' and the denominator (D) represents the number of operations
+ ' completed during the last sample interval.
+ '
+ ' Average - ((Nx - N0) / F) / (Dx - D0)
+ '
+ ' Example - PhysicalDisk\ Avg. Disk sec/Transfer
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ Private Shared Function MyComputeCounterValue( _
+ s0 As CounterSample, _
+ s1 As CounterSample) As Single
+ Dim n1 As Int64 = s1.RawValue
+ Dim n0 As Int64 = s0.RawValue
+ Dim f As Decimal = CType(s1.SystemFrequency, Decimal)
+ Dim d1 As Int64 = s1.BaseValue
+ Dim d0 As Int64 = s0.BaseValue
+
+ Dim numerator As Double = System.Convert.ToDouble(n1 - n0)
+ Dim denominator As Double = System.Convert.ToDouble(d1 - d0)
+ Dim counterValue As Single = CType(numerator, Single)
+ counterValue = counterValue / CType(f, Single)
+ counterValue = counterValue / CType(denominator, Single)
+
+ Return counterValue
+ End Function
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(s As CounterSample)
+ Console.WriteLine("+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Cr _
+ + ControlChars.Lf)
+ Console.WriteLine((" BaseValue = " _
+ + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + _
+ s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + _
+ s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + _
+ s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + _
+ s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + _
+ s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + _
+ s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + _
+ s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+
+ _
+ Public Shared Function _
+ QueryPerformanceCounter(ByRef value As Long) As Boolean
+ End Function
+
+End Class
+
+'
+
+#Else
+
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.InteropServices
+Imports System.Runtime.Versioning
+
+
+Public Class App
+
+ Private Const categoryName As String = "AverageTimer32SampleCategory"
+ Private Const counterName As String = "AverageTimer32Sample"
+ Private Const baseCounterName As String = "AverageTimer32SampleBase"
+
+ Private Shared PC As PerformanceCounter
+ Private Shared BPC As PerformanceCounter
+
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ SetupCategory()
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+
+ If Not PerformanceCounterCategory.Exists(categoryName) Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim averageTimer32 As New CounterCreationData()
+ averageTimer32.CounterType = PerformanceCounterType.AverageTimer32
+ averageTimer32.CounterName = counterName
+ CCDC.Add(averageTimer32)
+
+ ' Add the base counter.
+ Dim averageTimer32Base As New CounterCreationData()
+ averageTimer32Base.CounterType = PerformanceCounterType.AverageBase
+ averageTimer32Base.CounterName = baseCounterName
+ CCDC.Add(averageTimer32Base)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create( _
+ categoryName, _
+ "Demonstrates usage of the AverageTimer32 performance counter type", _
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Console.WriteLine("Category created - " + categoryName)
+
+ Return True
+ Else
+ Console.WriteLine(("Category exists - " + _
+ categoryName))
+ Return False
+ End If
+ End Function
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+ PC = New PerformanceCounter(categoryName, _
+ counterName, False)
+
+ BPC = New PerformanceCounter(categoryName, _
+ baseCounterName, False)
+
+ PC.RawValue = 0
+ BPC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Loop for the samples.
+ Dim i As Integer
+ For i = 0 To 9
+
+ PC.RawValue = Stopwatch.GetTimeStamp()
+
+ BPC.IncrementBy(10)
+
+ System.Threading.Thread.Sleep(1000)
+ Console.WriteLine(("Next value = " + PC.NextValue().ToString()))
+ samplesList.Add(PC.NextSample())
+ Next i
+ End Sub
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ Dim sample1 As CounterSample
+ Dim sample2 As CounterSample
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ sample1 = CType(samplesList(i), CounterSample)
+ sample2 = CType(samplesList(i + 1), CounterSample)
+ OutputSample(sample1)
+ OutputSample(sample2)
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine((".NET computed counter value = " _
+ + CounterSample.Calculate(sample1, sample2).ToString()))
+
+ ' Calculate the counter value manually.
+ Console.WriteLine(("My computed counter value = " _
+ + MyComputeCounterValue(sample1, sample2).ToString()))
+
+ Next i
+ End Sub
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ ' PERF_AVERAGE_TIMER
+ ' Description - This counter type measures the time it takes, on
+ ' average, to complete a process or operation. Counters of this
+ ' type display a ratio of the total elapsed time of the sample
+ ' interval to the number of processes or operations completed
+ ' during that time. This counter type measures time in ticks
+ ' of the system clock. The F variable represents the number of
+ ' ticks per second. The value of F is factored into the equation
+ ' so that the result can be displayed in seconds.
+ '
+ ' Generic type - Average
+ '
+ ' Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
+ ' represents the number of ticks counted during the last
+ ' sample interval, F represents the frequency of the ticks,
+ ' and the denominator (D) represents the number of operations
+ ' completed during the last sample interval.
+ '
+ ' Average - ((Nx - N0) / F) / (Dx - D0)
+ '
+ ' Example - PhysicalDisk\ Avg. Disk sec/Transfer
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
+ Private Shared Function MyComputeCounterValue( _
+ ByVal s0 As CounterSample, _
+ ByVal s1 As CounterSample) As Single
+ Dim n1 As Int64 = s1.RawValue
+ Dim n0 As Int64 = s0.RawValue
+ Dim f As Decimal = CType(s1.SystemFrequency, Decimal)
+ Dim d1 As Int64 = s1.BaseValue
+ Dim d0 As Int64 = s0.BaseValue
+
+ Dim numerator As Double = System.Convert.ToDouble(n1 - n0)
+ Dim denominator As Double = System.Convert.ToDouble(d1 - d0)
+ Dim counterValue As Single = CType(numerator, Single)
+ counterValue = counterValue / CType(f, Single)
+ counterValue = counterValue / CType(denominator, Single)
+
+ Return counterValue
+ End Function
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine("+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Cr _
+ + ControlChars.Lf)
+ Console.WriteLine((" CounterType = " + _
+ s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + _
+ s.RawValue.ToString()))
+ Console.WriteLine((" BaseValue = " _
+ + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + _
+ s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + _
+ s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" SystemFrequency = " + _
+ s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + _
+ s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + _
+ s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+
+
+End Class
+
+'
+
+#End If
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/elapsedtime.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/elapsedtime.vb
new file mode 100644
index 00000000000..abcbfba55d2
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/elapsedtime.vb
@@ -0,0 +1,237 @@
+' Notice that the sample is conditionally compiled for Everett vs.
+' Whidbey builds. Whidbey introduced new APIs that are not available
+' in Everett. Snippet IDs do not overlap between Whidbey and Everett;
+' Snippet #1 is Everett, Snippet #2 and #3 are Whidbey.
+
+#If BELOW_WHIDBEY_BUILD Then
+
+ '
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.InteropServices
+
+Public Class App2
+ Private Shared PC As PerformanceCounter
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the App2lication that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ End If
+
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+ If Not PerformanceCounterCategory.Exists("ElapsedTimeSampleCategory") Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim ETimeData As New CounterCreationData()
+ ETimeData.CounterType = PerformanceCounterType.ElapsedTime
+ ETimeData.CounterName = "ElapsedTimeSample"
+ CCDC.Add(ETimeData)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("ElapsedTimeSampleCategory", _
+ "Demonstrates usage of the ElapsedTime performance counter type.", CCDC)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - ElapsedTimeSampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counter.
+ PC = New PerformanceCounter("ElapsedTimeSampleCategory", _
+ "ElapsedTimeSample", False)
+ End Sub
+
+
+
+ Private Shared Sub CollectSamples(samplesList As ArrayList)
+
+ Dim pcValue As Long
+ Dim Start As DateTime
+
+ ' Initialize the counter.
+ QueryPerformanceCounter(pcValue)
+ PC.RawValue = pcValue
+ Start = DateTime.Now
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 999
+ ' Output the values.
+ If j Mod 10 = 9 Then
+ Console.WriteLine(("NextValue() = " _
+ + PC.NextValue().ToString()))
+ Console.WriteLine(("Actual elapsed time = " _
+ + DateTime.Now.Subtract(Start).ToString()))
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ End If
+
+ ' reset the counter on 100th iteration.
+ If j Mod 100 = 0 Then
+ QueryPerformanceCounter(pcValue)
+ PC.RawValue = pcValue
+ Start = DateTime.Now
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+
+ Console.WriteLine(("Elapsed time = " + _
+ DateTime.Now.Subtract(Start).ToString()))
+ End Sub
+
+
+ Private Shared Sub OutputSample(s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++")
+
+ Console.WriteLine("Sample values - " + ControlChars.Cr _
+ + ControlChars.Lf)
+ Console.WriteLine((" BaseValue = " _
+ + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + _
+ s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + _
+ s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + _
+ s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + _
+ s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + _
+ s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + _
+ s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + _
+ s.TimeStamp100nSec.ToString()))
+
+ Console.WriteLine("+++++++")
+ End Sub
+
+ ' Reads the counter information to enable setting the RawValue.
+ _
+ Public Shared Function _
+ QueryPerformanceCounter(ByRef value As Long) As Boolean
+ End Function
+End Class
+'
+
+#Else
+'
+
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.InteropServices
+Imports System.Runtime.Versioning
+
+
+Public Class App2
+
+ Public Shared Sub Main()
+ CollectSamples()
+ End Sub
+
+ Private Shared Sub CollectSamples()
+
+ Dim categoryName As String = "ElapsedTimeSampleCategory"
+ Dim counterName As String = "ElapsedTimeSample"
+
+ If Not PerformanceCounterCategory.Exists(categoryName) Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim ETimeData As New CounterCreationData()
+ ETimeData.CounterType = PerformanceCounterType.ElapsedTime
+ ETimeData.CounterName = counterName
+ CCDC.Add(ETimeData)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create(categoryName,
+ "Demonstrates ElapsedTime performance counter usage.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Else
+ Console.WriteLine("Category exists - {0}", categoryName)
+ End If
+
+ '
+ ' Create the counter.
+ Dim PC As PerformanceCounter
+ PC = New PerformanceCounter(categoryName, counterName, False)
+
+ ' Initialize the counter.
+ PC.RawValue = Stopwatch.GetTimestamp()
+ '
+
+ Dim Start As DateTime = DateTime.Now
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+ ' Output the values.
+ If j Mod 10 = 9 Then
+ Console.WriteLine(("NextValue() = " _
+ + PC.NextValue().ToString()))
+ Console.WriteLine(("Actual elapsed time = " _
+ + DateTime.Now.Subtract(Start).ToString()))
+ OutputSample(PC.NextSample())
+ End If
+
+ ' Reset the counter every 20th iteration.
+ If j Mod 20 = 0 Then
+ PC.RawValue = Stopwatch.GetTimestamp()
+ Start = DateTime.Now
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+
+ Console.WriteLine(("Elapsed time = " +
+ DateTime.Now.Subtract(Start).ToString()))
+ End Sub
+
+
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++")
+
+ Console.WriteLine("Sample values - " + ControlChars.Cr _
+ + ControlChars.Lf)
+ Console.WriteLine((" BaseValue = " _
+ + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " +
+ s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " +
+ s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " +
+ s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " +
+ s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " +
+ s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " +
+ s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " +
+ s.TimeStamp100nSec.ToString()))
+
+ Console.WriteLine("+++++++")
+ End Sub
+End Class
+'
+
+#End If
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.vb
new file mode 100644
index 00000000000..c075e12f5fb
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.vb
@@ -0,0 +1,131 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class NumberOfItems64
+
+ Private Shared PC As PerformanceCounter
+
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the application that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+ If Not PerformanceCounterCategory.Exists("NumberOfItems32SampleCategory") Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim NOI64 As New CounterCreationData()
+ NOI64.CounterType = PerformanceCounterType.NumberOfItems64
+ NOI64.CounterName = "NumberOfItems32Sample"
+ CCDC.Add(NOI64)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("NumberOfItems32SampleCategory", _
+ "Demonstrates usage of the NumberOfItems32 performance counter type.", _
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - NumberOfItems32SampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counter.
+ PC = New PerformanceCounter("NumberOfItems32SampleCategory", "NumberOfItems32Sample", False)
+
+ PC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ Dim value As Integer = r.Next(1, 10)
+ Console.Write(j.ToString() + " = " + value.ToString())
+
+ PC.IncrementBy(value)
+
+ If j Mod 10 = 9 Then
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+
+
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+ Next i
+ End Sub
+
+
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim counterValue As [Single] = s1.RawValue
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine(" BaseValue = " + s.BaseValue.ToString())
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency.ToString())
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp.ToString())
+ Console.WriteLine(" CounterType = " + s.CounterType.ToString())
+ Console.WriteLine(" RawValue = " + s.RawValue.ToString())
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency.ToString())
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp.ToString())
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString())
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+
+
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.vb
new file mode 100644
index 00000000000..7708ef509b9
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.vb
@@ -0,0 +1,126 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class NumberOfItems64_1
+
+ Private Shared PC As PerformanceCounter
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the application that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+ If Not PerformanceCounterCategory.Exists("NumberOfItems64SampleCategory") Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim NOI64 As New CounterCreationData()
+ NOI64.CounterType = PerformanceCounterType.NumberOfItems64
+ NOI64.CounterName = "NumberOfItems64Sample"
+ CCDC.Add(NOI64)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("NumberOfItems64SampleCategory",
+ "Demonstrates usage of the NumberOfItems64_1 performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - NumberOfItems64SampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+ PC = New PerformanceCounter("NumberOfItems64SampleCategory", "NumberOfItems64Sample", False)
+
+ PC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ Dim value As Integer = r.Next(1, 10)
+ Console.Write((j.ToString() + " = " + value.ToString()))
+
+ PC.IncrementBy(value)
+
+ If j Mod 10 = 9 Then
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+ Next i
+ End Sub
+
+
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim counterValue As [Single] = s1.RawValue
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/program.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/program.vb
new file mode 100644
index 00000000000..029e8b13ea9
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/program.vb
@@ -0,0 +1,153 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+' Provides a SampleFraction counter to measure the percentage of the user processor
+' time for this process to total processor time for the process.
+
+
+Public Class App3
+
+ Private Shared perfCounter As PerformanceCounter
+ Private Shared basePerfCounter As PerformanceCounter
+ Private Shared thisProcess As Process = Process.GetCurrentProcess()
+
+
+ Public Shared Sub Main()
+
+ Dim samplesList As New ArrayList()
+
+ ' If the category does not exist, create the category and exit.
+ ' Performance counters should not be created and immediately used.
+ ' There is a latency time to enable the counters, they should be created
+ ' prior to executing the application that uses the counters.
+ ' Execute this sample a second time to use the category.
+ If SetupCategory() Then
+ Return
+ End If
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+
+ End Sub
+
+
+
+ Private Shared Function SetupCategory() As Boolean
+ If Not PerformanceCounterCategory.Exists("SampleFractionCategory") Then
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim sampleFraction As New CounterCreationData()
+ sampleFraction.CounterType = PerformanceCounterType.SampleFraction
+ sampleFraction.CounterName = "SampleFractionSample"
+ CCDC.Add(sampleFraction)
+
+ ' Add the base counter.
+ Dim sampleFractionBase As New CounterCreationData()
+ sampleFractionBase.CounterType = PerformanceCounterType.SampleBase
+ sampleFractionBase.CounterName = "SampleFractionSampleBase"
+ CCDC.Add(sampleFractionBase)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("SampleFractionCategory", "Demonstrates usage of the SampleFraction performance counter type.", PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - SampleFractionCategory")
+ Return False
+ End If
+
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+ perfCounter = New PerformanceCounter("SampleFractionCategory", "SampleFractionSample", False)
+
+
+ basePerfCounter = New PerformanceCounter("SampleFractionCategory", "SampleFractionSampleBase", False)
+
+
+ perfCounter.RawValue = thisProcess.UserProcessorTime.Ticks
+ basePerfCounter.RawValue = thisProcess.TotalProcessorTime.Ticks
+
+ End Sub
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ perfCounter.IncrementBy(thisProcess.UserProcessorTime.Ticks)
+
+ basePerfCounter.IncrementBy(thisProcess.TotalProcessorTime.Ticks)
+
+ If j Mod 10 = 9 Then
+ OutputSample(perfCounter.NextSample())
+ samplesList.Add(perfCounter.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+
+ End Sub
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1)
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)))
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)))
+ Next i
+
+ End Sub
+
+
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ ' Description - This counter type provides A percentage counter that shows the
+ ' average ratio of user proccessor time to total processor time during the last
+ ' two sample intervals.
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim numerator As [Single] = CType(s1.RawValue, [Single]) - CType(s0.RawValue, [Single])
+ Dim denomenator As [Single] = CType(s1.BaseValue, [Single]) - CType(s0.BaseValue, [Single])
+ Dim counterValue As [Single] = 100 * (numerator / denomenator)
+ Return counterValue
+
+ End Function 'MyComputeCounterValue
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(vbCr + vbLf + "+++++++++++")
+ Console.WriteLine("Sample values - " + vbCr + vbLf)
+ Console.WriteLine(" BaseValue = " + s.BaseValue)
+ Console.WriteLine(" CounterFrequency = " + s.CounterFrequency)
+ Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp)
+ Console.WriteLine(" CounterType = " + s.CounterType)
+ Console.WriteLine(" RawValue = " + s.RawValue)
+ Console.WriteLine(" SystemFrequency = " + s.SystemFrequency)
+ Console.WriteLine(" TimeStamp = " + s.TimeStamp)
+ Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec)
+ Console.WriteLine("++++++++++++++++++++++")
+
+ End Sub
+End Class
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.vb
new file mode 100644
index 00000000000..e4b597c0e5a
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.vb
@@ -0,0 +1,151 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class App4
+ Private Shared PC As PerformanceCounter
+
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the App4lication that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+
+ If Not PerformanceCounterCategory.Exists("RateOfCountsPerSecond32SampleCategory") Then
+
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim rateOfCounts32 As New CounterCreationData()
+ rateOfCounts32.CounterType = PerformanceCounterType.RateOfCountsPerSecond32
+ rateOfCounts32.CounterName = "RateOfCountsPerSecond32Sample"
+ CCDC.Add(rateOfCounts32)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("RateOfCountsPerSecond32SampleCategory", _
+ "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.", _
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+ Return True
+ Else
+ Console.WriteLine("Category exists - RateOfCountsPerSecond32SampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counter.
+ PC = New PerformanceCounter("RateOfCountsPerSecond32SampleCategory", "RateOfCountsPerSecond32Sample", False)
+
+ PC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Initialize the performance counter.
+ PC.NextSample()
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ Dim value As Integer = r.Next(1, 10)
+ PC.IncrementBy(value)
+ Console.Write((j.ToString() + " = " + value.ToString()))
+
+ If j Mod 10 = 9 Then
+ Console.WriteLine(("; NextValue() = " + PC.NextValue().ToString()))
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+ Next i
+ End Sub
+
+
+
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ ' PERF_COUNTER_COUNTER
+ ' Description - This counter type shows the average number of operations completed
+ ' during each second of the sample interval. Counters of this type
+ ' measure time in ticks of the system clock. The F variable represents
+ ' the number of ticks per second. The value of F is factored into the
+ ' equation so that the result can be displayed in seconds.
+ '
+ ' Generic type - Difference
+ '
+ ' Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
+ ' of operations performed during the last sample interval, the denominator
+ ' (D) represents the number of ticks elapsed during the last sample
+ ' interval, and F is the frequency of the ticks.
+ '
+ ' Average - (Nx - N0) / ((Dx - D0) / F)
+ '
+ ' Example - System\ File Read Operations/sec
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim numerator As [Single] = CType(s1.RawValue - s0.RawValue, [Single])
+ Dim denomenator As [Single] = CType(s1.TimeStamp - s0.TimeStamp, [Single]) / CType(s1.SystemFrequency, [Single])
+ Dim counterValue As [Single] = numerator / denomenator
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.vb
new file mode 100644
index 00000000000..ea2d3f1f8f7
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.vb
@@ -0,0 +1,151 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class App5
+ Private Shared PC As PerformanceCounter
+
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the App5lication that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+ End Sub
+
+
+ Private Shared Function SetupCategory() As Boolean
+
+
+ If Not PerformanceCounterCategory.Exists("RateOfCountsPerSecond64SampleCategory") Then
+
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim rateOfCounts64 As New CounterCreationData()
+ rateOfCounts64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64
+ rateOfCounts64.CounterName = "RateOfCountsPerSecond64Sample"
+ CCDC.Add(rateOfCounts64)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("RateOfCountsPerSecond64SampleCategory", _
+ "Demonstrates usage of the RateOfCountsPerSecond64 performance counter type.", _
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+ Return True
+ Else
+ Console.WriteLine("Category exists - RateOfCountsPerSecond64SampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counter.
+ PC = New PerformanceCounter("RateOfCountsPerSecond64SampleCategory", "RateOfCountsPerSecond64Sample", False)
+
+ PC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Initialize the performance counter.
+ PC.NextSample()
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+
+ Dim value As Integer = r.Next(1, 10)
+ PC.IncrementBy(value)
+ Console.Write((j.ToString() + " = " + value.ToString()))
+
+ If j Mod 10 = 9 Then
+ Console.WriteLine(("; NextValue() = " + PC.NextValue().ToString()))
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To (samplesList.Count - 1) - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+ OutputSample(CType(samplesList((i + 1)), CounterSample))
+
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + _
+ CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + _
+ MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample)).ToString())
+ Next i
+ End Sub
+
+
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ ' PERF_COUNTER_COUNTER
+ ' Description - This counter type shows the average number of operations completed
+ ' during each second of the sample interval. Counters of this type
+ ' measure time in ticks of the system clock. The F variable represents
+ ' the number of ticks per second. The value of F is factored into the
+ ' equation so that the result can be displayed in seconds.
+ '
+ ' Generic type - Difference
+ '
+ ' Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
+ ' of operations performed during the last sample interval, the denominator
+ ' (D) represents the number of ticks elapsed during the last sample
+ ' interval, and F is the frequency of the ticks.
+ '
+ ' Average - (Nx - N0) / ((Dx - D0) / F)
+ '
+ ' Example - System\ File Read Operations/sec
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal s0 As CounterSample, ByVal s1 As CounterSample) As [Single]
+ Dim numerator As [Single] = CType(s1.RawValue - s0.RawValue, [Single])
+ Dim denomenator As [Single] = CType(s1.TimeStamp - s0.TimeStamp, [Single]) / CType(s1.SystemFrequency, [Single])
+ Dim counterValue As [Single] = numerator / denomenator
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+
+'
diff --git a/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.vb b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.vb
new file mode 100644
index 00000000000..3c0595ecf34
--- /dev/null
+++ b/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.vb
@@ -0,0 +1,162 @@
+'
+Imports System.Collections
+Imports System.Collections.Specialized
+Imports System.Diagnostics
+Imports System.Runtime.Versioning
+
+
+Public Class App6
+ Private Shared PC As PerformanceCounter
+ Private Shared BPC As PerformanceCounter
+
+ Public Shared Sub Main()
+ Dim samplesList As New ArrayList()
+
+ 'If the category does not exist, create the category and exit.
+ 'Performance counters should not be created and immediately used.
+ 'There is a latency time to enable the counters, they should be created
+ 'prior to executing the App6lication that uses the counters.
+ 'Execute this sample a second time to use the counters.
+ If Not (SetupCategory()) Then
+ CreateCounters()
+ CollectSamples(samplesList)
+ CalculateResults(samplesList)
+ End If
+
+ End Sub
+
+ Private Shared Function SetupCategory() As Boolean
+
+
+ If Not PerformanceCounterCategory.Exists("RawFractionSampleCategory") Then
+
+
+ Dim CCDC As New CounterCreationDataCollection()
+
+ ' Add the counter.
+ Dim rf As New CounterCreationData()
+ rf.CounterType = PerformanceCounterType.RawFraction
+ rf.CounterName = "RawFractionSample"
+ CCDC.Add(rf)
+
+ ' Add the base counter.
+ Dim rfBase As New CounterCreationData()
+ rfBase.CounterType = PerformanceCounterType.RawBase
+ rfBase.CounterName = "RawFractionSampleBase"
+ CCDC.Add(rfBase)
+
+ ' Create the category.
+ PerformanceCounterCategory.Create("RawFractionSampleCategory",
+ "Demonstrates usage of the RawFraction performance counter type.",
+ PerformanceCounterCategoryType.SingleInstance, CCDC)
+
+ Return True
+ Else
+ Console.WriteLine("Category exists - RawFractionSampleCategory")
+ Return False
+ End If
+ End Function 'SetupCategory
+
+
+ Private Shared Sub CreateCounters()
+ ' Create the counters.
+ PC = New PerformanceCounter("RawFractionSampleCategory", "RawFractionSample", False)
+
+ BPC = New PerformanceCounter("RawFractionSampleCategory", "RawFractionSampleBase", False)
+
+ PC.RawValue = 0
+ BPC.RawValue = 0
+ End Sub
+
+
+ Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)
+
+ Dim r As New Random(DateTime.Now.Millisecond)
+
+ ' Initialize the performance counter.
+ PC.NextSample()
+
+ ' Loop for the samples.
+ Dim j As Integer
+ For j = 0 To 99
+ Dim value As Integer = r.Next(1, 10)
+ Console.Write((j.ToString() + " = " + value.ToString()))
+
+ ' Increment the base every time, because the counter measures the number
+ ' of high hits (raw fraction value) against all the hits (base value).
+ BPC.Increment()
+
+ ' Get the % of samples that are 9 or 10 out of all the samples taken.
+ If value >= 9 Then
+ PC.Increment()
+ End If
+ ' Copy out the next value every ten times around the loop.
+ If j Mod 10 = 9 Then
+ Console.WriteLine(("; NextValue() = " + PC.NextValue().ToString()))
+ OutputSample(PC.NextSample())
+ samplesList.Add(PC.NextSample())
+ Else
+ Console.WriteLine()
+ End If
+ System.Threading.Thread.Sleep(50)
+ Next j
+ End Sub
+
+
+
+ Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
+ Dim i As Integer
+ For i = 0 To samplesList.Count - 1
+ ' Output the sample.
+ OutputSample(CType(samplesList(i), CounterSample))
+
+ ' Use .NET to calculate the counter value.
+ Console.WriteLine(".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample)).ToString())
+
+ ' Calculate the counter value manually.
+ Console.WriteLine("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample)).ToString())
+ Next i
+ End Sub
+
+
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ ' Formula from MSDN -
+ ' Description - This counter type shows the ratio of a subset to its set as a percentage.
+ ' For example, it compares the number of bytes in use on a disk to the
+ ' total number of bytes on the disk. Counters of this type display the
+ ' current percentage only, not an average over time.
+ '
+ ' Generic type - Instantaneous, Percentage
+ ' Formula - (N0 / D0), where D represents a measured attribute and N represents one
+ ' component of that attribute.
+ '
+ ' Average - SUM (N / D) /x
+ ' Example - Paging File\% Usage Peak
+ '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
+ Private Shared Function MyComputeCounterValue(ByVal rfSample As CounterSample) As [Single]
+ Dim numerator As [Single] = CType(rfSample.RawValue, [Single])
+ Dim denomenator As [Single] = CType(rfSample.BaseValue, [Single])
+ Dim counterValue As [Single] = numerator / denomenator * 100
+ Return counterValue
+ End Function 'MyComputeCounterValue
+
+
+ ' Output information about the counter sample.
+ Private Shared Sub OutputSample(ByVal s As CounterSample)
+ Console.WriteLine("+++++++++++")
+ Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
+ Console.WriteLine((" BaseValue = " + s.BaseValue.ToString()))
+ Console.WriteLine((" CounterFrequency = " + s.CounterFrequency.ToString()))
+ Console.WriteLine((" CounterTimeStamp = " + s.CounterTimeStamp.ToString()))
+ Console.WriteLine((" CounterType = " + s.CounterType.ToString()))
+ Console.WriteLine((" RawValue = " + s.RawValue.ToString()))
+ Console.WriteLine((" SystemFrequency = " + s.SystemFrequency.ToString()))
+ Console.WriteLine((" TimeStamp = " + s.TimeStamp.ToString()))
+ Console.WriteLine((" TimeStamp100nSec = " + s.TimeStamp100nSec.ToString()))
+ Console.WriteLine("++++++++++++++++++++++")
+ End Sub
+End Class
+
+
+
+'
diff --git a/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Class1.vb b/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Class1.vb
new file mode 100644
index 00000000000..6a43c757640
--- /dev/null
+++ b/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Class1.vb
@@ -0,0 +1,128 @@
+Option Explicit On
+Option Strict On
+
+Imports System.Windows.Forms
+Imports System.Drawing
+Imports System.Collections
+Imports System.Xml
+Imports System.Drawing.Imaging
+Imports System.Drawing.Drawing2D
+
+Public Class Form1
+ Inherits Form
+
+ _
+ Public Shared Sub Main()
+ Application.EnableVisualStyles()
+ Application.Run(New Form1())
+ End Sub
+
+ Dim myPen As Pen = Pens.Black
+ ' 0659fe00-9e0c-41c4-9118-016f2404c905
+ ' Matrix Representation of Transformations
+ Public Sub Method11()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ Dim myMatrix As New Matrix()
+ myMatrix.Rotate(30)
+ myMatrix.Scale(1, 2, MatrixOrder.Append)
+ myMatrix.Translate(5, 0, MatrixOrder.Append)
+
+ '
+ End Sub
+ ' b601d66d-d572-4f11-9d2e-92f0dc8893f3
+ ' Global and Local Transformations
+ Public Sub Method21()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ myGraphics.DrawEllipse(myPen, 0, 0, 100, 50)
+ myGraphics.ScaleTransform(1, 0.5F)
+ myGraphics.TranslateTransform(50, 0, MatrixOrder.Append)
+ myGraphics.RotateTransform(30, MatrixOrder.Append)
+ myGraphics.DrawEllipse(myPen, 0, 0, 100, 50)
+
+ '
+ End Sub
+ Public Sub Method22()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ Dim myGraphicsPath As New GraphicsPath()
+ '
+ Dim myMatrix As New Matrix()
+ myMatrix.Rotate(45)
+ myGraphicsPath.Transform(myMatrix)
+ myGraphics.DrawRectangle(myPen, 10, 10, 100, 50)
+ myGraphics.DrawPath(myPen, myGraphicsPath)
+
+ '
+ End Sub
+ Public Sub Method23()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ Dim myMatrix As New Matrix(1, 0, 0, -1, 0, 0)
+ myGraphics.Transform = myMatrix
+ myGraphics.TranslateTransform(200, 150, MatrixOrder.Append)
+
+ '
+ End Sub
+ Public Sub Method24()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ Dim mySolidBrush1 As New SolidBrush(Color.Red)
+ Dim mySolidBrush2 As New SolidBrush(Color.Black)
+
+ '
+ ' Create the path.
+ Dim myGraphicsPath As New GraphicsPath()
+ Dim myRectangle As New Rectangle(0, 0, 60, 60)
+ myGraphicsPath.AddRectangle(myRectangle)
+
+ ' Fill the path on the new coordinate system.
+ ' No local transformation
+ myGraphics.FillPath(mySolidBrush1, myGraphicsPath)
+
+ ' Set the local transformation of the GraphicsPath object.
+ Dim myPathMatrix As New Matrix()
+ myPathMatrix.Scale(2, 1)
+ myPathMatrix.Rotate(30, MatrixOrder.Append)
+ myGraphicsPath.Transform(myPathMatrix)
+
+ ' Fill the transformed path on the new coordinate system.
+ myGraphics.FillPath(mySolidBrush2, myGraphicsPath)
+
+ '
+ End Sub
+ ' c61ff50a-eb1d-4e6c-83cd-f7e9764cfa9f
+ ' Types of Coordinate Systems
+ Public Sub Method31()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ myGraphics.TranslateTransform(100, 50)
+ myGraphics.DrawLine(myPen, 0, 0, 160, 80)
+
+ '
+ End Sub
+ Public Sub Method32()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ myGraphics.PageUnit = GraphicsUnit.Inch
+ myGraphics.DrawLine(myPen, 0, 0, 2, 1)
+
+ '
+ End Sub
+ Public Sub Method33()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ Dim myPen As New Pen(Color.Black, 1 / myGraphics.DpiX)
+
+ '
+ End Sub
+ Public Sub Method34()
+ Dim myGraphics As Graphics = Me.CreateGraphics()
+ '
+ myGraphics.TranslateTransform(2, 0.5F)
+ myGraphics.PageUnit = GraphicsUnit.Inch
+ myGraphics.DrawLine(myPen, 0, 0, 2, 1)
+
+ '
+ End Sub
+End Class
+
diff --git a/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Project.vbproj b/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Project.vbproj
new file mode 100644
index 00000000000..c86794b1506
--- /dev/null
+++ b/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Project.vbproj
@@ -0,0 +1,9 @@
+
+
+
+ WinExe
+ net48
+ true
+
+
+
diff --git a/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/Project.vbproj b/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/Project.vbproj
new file mode 100644
index 00000000000..874c98f3477
--- /dev/null
+++ b/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/Project.vbproj
@@ -0,0 +1,8 @@
+
+
+
+ Library
+ net10.0
+
+
+
diff --git a/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb b/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb
new file mode 100644
index 00000000000..ec306ff784c
--- /dev/null
+++ b/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb
@@ -0,0 +1,109 @@
+Imports System.Dynamic
+Imports System.ComponentModel
+Imports System.Linq
+Imports System.Collections.Generic
+
+Module Module2
+
+ Sub Test()
+ '
+ Dim sampleObject As Object = New ExpandoObject()
+ '
+
+ '
+ sampleObject.Test = "Dynamic Property"
+ Console.WriteLine(sampleObject.test)
+ Console.WriteLine(sampleObject.test.GetType())
+ ' This code example produces the following output:
+ ' Dynamic Property
+ ' System.String
+ '
+
+ '
+ sampleObject.Number = 10
+ sampleObject.Increment = Function() sampleObject.Number + 1
+ ' Before calling the Increment method.
+ Console.WriteLine(sampleObject.number)
+
+ sampleObject.Increment.Invoke()
+
+ ' After calling the Increment method.
+ Console.WriteLine(sampleObject.number)
+ ' This code example produces the following output:
+ ' 10
+ ' 11
+ '
+
+ '
+ Dim employee As Object = New ExpandoObject()
+ employee.Name = "John Smith"
+ employee.Age = 33
+ For Each member In CType(employee, IDictionary(Of String, Object))
+ Console.WriteLine(member.Key & ": " & member.Value)
+ Next
+ ' This code example produces the following output:
+ ' Name: John Smith
+ ' Age: 33
+ '
+ End Sub
+
+ Sub Test2()
+ '
+ Dim employee As Object = New ExpandoObject()
+ employee.Name = "John Smith"
+ CType(employee, IDictionary(Of String, Object)).Remove("Name")
+ '
+ End Sub
+
+End Module
+
+Module Module1
+
+ '
+ Sub Main()
+ Dim employee, manager As Object
+
+ employee = New ExpandoObject()
+ employee.Name = "John Smith"
+ employee.Age = 33
+
+ manager = New ExpandoObject()
+ manager.Name = "Allison Brown"
+ manager.Age = 42
+ manager.TeamSize = 10
+
+ WritePerson(manager)
+ WritePerson(employee)
+ End Sub
+
+ Private Sub WritePerson(ByVal person As Object)
+
+ Console.WriteLine("{0} is {1} years old.",
+ person.Name, person.Age)
+ ' The following statement causes an exception
+ ' if you pass the employee object.
+ ' Console.WriteLine("Manages {0} people", person.TeamSize)
+
+ End Sub
+ '
+End Module
+
+Module M3
+ '
+ ' Add "Imports System.ComponentModel" line
+ ' to the beginning of the file.
+ Sub Main()
+ Dim employee As Object = New ExpandoObject
+ AddHandler CType(
+ employee, INotifyPropertyChanged).PropertyChanged,
+ AddressOf HandlePropertyChanges
+ employee.Name = "John Smith"
+ End Sub
+
+ Private Sub HandlePropertyChanges(
+ ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
+ Console.WriteLine("{0} has changed.", e.PropertyName)
+ End Sub
+ '
+End Module
+
diff --git a/xml/System.Data/CommandBehavior.xml b/xml/System.Data/CommandBehavior.xml
index 803169455d6..e51168089d6 100644
--- a/xml/System.Data/CommandBehavior.xml
+++ b/xml/System.Data/CommandBehavior.xml
@@ -52,7 +52,26 @@
Provides a description of the results of the query and its effect on the database.
- For more information about this API, see Supplemental API remarks for CommandBehavior.
+
+ method of and any implementing classes.
+
+A bitwise combination of these values may be used.
+
+`CommandBehavior` is ignored when used to define a or and should therefore not be used. Use the constructor that does not require a `CommandBehavior` parameter in these two cases.
+
+## Notes on individual enumeration members
+
+When using `KeyInfo`, .NET Framework Data Provider for SQL Server precedes the statement being executed with `SET FMTONLY OFF` and `SET NO_BROWSETABLE ON`. Users should be aware of potential side effects, such as interference with the use of `SET FMTONLY ON` statements. For more information, see [SET FMTONLY (Transact-SQL)](/sql/t-sql/statements/set-fmtonly-transact-sql).
+
+> [!NOTE]
+> Use `SequentialAccess` to retrieve large values and binary data. Otherwise, an might occur and the connection will be closed.
+
+When you specify `SequentialAccess`, you are required to read from the columns in the order they are returned, although you are not required to read each column. Once you have read past a location in the returned stream of data, data at or before that location can no longer be read from the `DataReader`. When using the , you can reread the current column value until reading past it. When using the , you can read a column value only once.
+
+ ]]>
+
diff --git a/xml/System.Data/DataColumn.xml b/xml/System.Data/DataColumn.xml
index 3d67fa1d86a..51687816a66 100644
--- a/xml/System.Data/DataColumn.xml
+++ b/xml/System.Data/DataColumn.xml
@@ -1385,7 +1385,301 @@ myDataTable.Rows[0][0] = newValue;
Gets or sets the expression used to filter rows, calculate the values in a column, or create an aggregate column.
An expression to calculate the value of a column, or create an aggregate column. The return type of an expression is determined by the of the column.
- For more information about this API, see Supplemental API remarks for DataColumn.Expression.
+
+ property is to create calculated columns. For example, to calculate a tax value, the unit price is multiplied by a tax rate of a specific region. Because tax rates vary from region to region, it would be impossible to put a single tax rate in a column; instead, the value is calculated using the property, as shown in the following code:
+
+```vb
+DataSet1.Tables("Products").Columns("tax").Expression = "UnitPrice * 0.086"
+```
+
+A second use is to create an aggregate column. Similar to a calculated value, an aggregate performs an operation based on the complete set of rows in the . A simple example is to count the number of rows returned in the set. This is the method you would use to count the number of transactions completed by a particular salesperson, as shown in the following code:
+
+```vb
+DataSet1.Tables("Orders").Columns("OrderCount").Expression = "Count(OrderID)"
+```
+
+## Expression syntax
+
+When you create an expression, use the property to refer to columns. For example, if the for one column is "UnitPrice", and another "Quantity", the expression is:
+
+`"UnitPrice * Quantity"`
+
+> [!NOTE]
+> If a column is used in an expression, then the expression is said to have a dependency on that column. If a dependent column is renamed or removed, no exception is thrown. An exception will be thrown when the now-broken expression column is accessed.
+
+When you create an expression for a filter, enclose strings with single quotation marks:
+
+`"LastName = 'Jones'"`
+
+If a column name contains any non-alphanumeric characters, starts with a digit, or matches (case-insensitively) any of the following reserved words, it requires special handling, as described in the following paragraphs.
+
+:::row:::
+ :::column:::
+ `And`
+ :::column-end:::
+ :::column:::
+ `Between`
+ :::column-end:::
+ :::column:::
+ `Child`
+ :::column-end:::
+ :::column:::
+ `False`
+ :::column-end:::
+:::row-end:::
+:::row:::
+ :::column:::
+ `In`
+ :::column-end:::
+ :::column:::
+ `Is`
+ :::column-end:::
+ :::column:::
+ `Like`
+ :::column-end:::
+ :::column:::
+ `Not`
+ :::column-end:::
+:::row-end:::
+:::row:::
+ :::column:::
+ `Null`
+ :::column-end:::
+ :::column:::
+ `Or`
+ :::column-end:::
+ :::column:::
+ `Parent`
+ :::column-end:::
+ :::column:::
+ `True`
+ :::column-end:::
+:::row-end:::
+
+If a column name satisfies one of the previous conditions, it must be wrapped in either square brackets or "\`" (grave accent) quotes. For example, to use a column named "Column#" in an expression, you would write either "[Column#]" or "\`Column#`":
+
+`Total * [Column#]`
+
+If the column name is enclosed in square brackets, then any ']' and '\\' characters (but not any other characters) in it must be escaped by prepending them with the backslash ("\\") character. If the column name is enclosed in grave accent characters, then it must not contain any grave accent characters. For example, a column named "Column[]\\" would be written:
+
+`Total * [Column[\]\\]`
+
+or
+
+Total * \`Column[]\\`
+
+## User-defined values
+
+User-defined values may be used within expressions to be compared with column values. String values should be enclosed within single quotation marks (and each single quotation character in a string value has to be escaped by prepending it with another single quotation character). Date values should be enclosed within pound signs (#) or single quotes (') based on the data provider. Decimals and scientific notation are permissible for numeric values. For example:
+
+`"FirstName = 'John'"`
+
+`"Price <= 50.00"`
+
+`"Birthdate < #1/31/2006#"`
+
+For columns that contain enumeration values, cast the value to an integer data type. For example:
+
+`"EnumColumn = 5"`
+
+## Parse literal expressions
+
+All literal expressions must be expressed in the invariant culture locale. When `DataSet` parses and converts literal expressions, it always uses the invariant culture, not the current culture.
+
+String literals are identified when there are single quotes surrounding the value. For example, `'John'`.
+
+`Boolean` literals are `true` and `false`; they aren't quoted in expressions.
+
+`Integer` literals [+-]?[0-9]+ are treated as `System.Int32`, `System.Int64`, or `System.Double`. `System.Double` can lose precision depending on how large the number is. For example, if the number in the literal is 2147483650, `DataSet` will first attempt to parse the number as an `Int32`. This won't succeed because the number is too large. In this case `DataSet`, parses the number as an `Int64`, which will succeed. If the literal is a number larger than the maximum value of an Int64, `DataSet` parses the literal using `Double`.
+
+Real literals that use scientific notation, such as 4.42372E-30, are parsed using `System.Double`.
+
+Real literals without scientific notation, but with a decimal point, are treated as `System.Decimal`. If the number exceeds the maximum or minimum values supported by `System.Decimal`, then it is parsed as a `System.Double`. For example:
+
+- 142526.144524 is converted to a `Decimal`.
+- 345262.78036719560925667 is treated as a `Double`.
+
+## Operators
+
+Concatenation is allowed using Boolean AND, OR, and NOT operators. You can use parentheses to group clauses and force precedence. The AND operator has precedence over other operators. For example:
+
+`(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'`
+
+When you create comparison expressions, the following operators are allowed:
+
+- \<
+- \>
+- \<=
+- \>=
+- =
+- `IN`
+- `LIKE`
+
+The following arithmetic operators are also supported in expressions:
+
+- \+ (addition)
+- \- (subtraction)
+- \* (multiplication)
+- / (division)
+- % (modulus)
+
+## String operators
+
+To concatenate a string, use the `+` character. The value of the property of the class determines whether string comparisons are case-sensitive. However, you can override that value with the property of the class.
+
+## Wildcard characters
+
+Both the `*` and `%` characters can be used interchangeably for wildcard characters in a LIKE comparison. If the string in a LIKE clause contains a `*` or `%`, those characters should be enclosed in brackets (`[]`). If a bracket is in the clause, each bracket character should be enclosed in brackets (for example `[[]` or `[]]`). A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. For example:
+
+- `"ItemName LIKE '*product*'"`
+- `"ItemName LIKE '*product'"`
+- `"ItemName LIKE 'product*'"`
+
+Wildcard characters are not allowed in the middle of a string. For example, `'te*xt'` is not allowed.
+
+## Parent/child relation referencing
+
+A parent table may be referenced in an expression by prepending the column name with `Parent`. For example, `Parent.Price` references the parent table's column named `Price`.
+
+When a child has more than one parent row, use `Parent(RelationName).ColumnName`. For example, `Parent(RelationName).Price` references the parent table's column named "Price" via the relation.
+
+A column in a child table may be referenced in an expression by prepending the column name with `Child`. However, because child relationships may return multiple rows, you must include the reference to the child column in an aggregate function. For example, `Sum(Child.Price)` would return the sum of the column named `Price` in the child table.
+
+If a table has more than one child, the syntax is: `Child(RelationName)`. For example, if a table has two child tables named `Customers` and `Orders`, and the object is named `Customers2Orders`, the reference would be as follows:
+
+`Avg(Child(Customers2Orders).Quantity)`
+
+## Aggregates
+
+The following aggregate types are supported:
+
+- `Sum` (Sum)
+- `Avg` (Average)
+- `Min` (Minimum)
+- `Max` (Maximum)
+- `Count` (Count)
+- `StDev` (Statistical standard deviation)
+- `Var` (Statistical variance)
+
+Aggregates are ordinarily performed along relationships. Create an aggregate expression by using one of the functions listed earlier and a child table column as detailed in [Parent/child relation referencing](#parentchild-relation-referencing). For example:
+
+- `Avg(Child.Price)`
+- `Avg(Child(Orders2Details).Price)`
+
+An aggregate can also be performed on a single table. For example, to create a summary of figures in a column named "Price":
+
+`Sum(Price)`
+
+> [!NOTE]
+> If you use a single table to create an aggregate, there would be no group-by functionality. Instead, all rows would display the same value in the column.
+
+If a table has no rows, the aggregate functions will return `null`.
+
+Data types can always be determined by examining the property of a column. You can also convert data types using the `Convert` function, shown in the following section.
+
+An aggregate can only be applied to a single column, and no other expressions can be used inside the aggregate.
+
+## Functions
+
+The following functions are also supported.
+
+### `CONVERT`
+
+This function converts an expression to a specified .NET type.
+
+```csharp
+Convert(expression, type)
+```
+
+| Argument | Description |
+|--------------|-------------------------------------------------|
+| `expression` | The expression to convert. |
+| `type` | .NET type to which the value will be converted. |
+
+Example: `myDataColumn.Expression="Convert(total, 'System.Int32')"`
+
+All conversions are valid with the following exceptions: `Boolean` can be coerced to and from `Byte`, `SByte`, `Int16`, `Int32`, `Int64`, `UInt16`, `UInt32`, `UInt64`, `String` and itself only. `Char` can be coerced to and from `Int32`, `UInt32`, `String`, and itself only. `DateTime` can be coerced to and from `String` and itself only. `TimeSpan` can be coerced to and from `String` and itself only.
+
+### `LEN`
+
+This function gets the length of a string.
+
+```csharp
+LEN(expression)
+```
+
+| Arguments | Description |
+|--------------|-----------------------------|
+| `expression` | The string to be evaluated. |
+
+Example: `myDataColumn.Expression="Len(ItemName)"`
+
+### `ISNULL`
+
+This function checks an expression and either returns the checked expression or a replacement value.
+
+```csharp
+ISNULL(expression, replacementvalue)
+```
+
+| Arguments | Description |
+|--------------------|----------------------------------------------------------|
+| `expression` | The expression to check. |
+| `replacementvalue` | If expression is `null`, `replacementvalue` is returned. |
+
+Example: `myDataColumn.Expression="IsNull(price, -1)"`
+
+### `IIF`
+
+This function gets one of two values depending on the result of a logical expression.
+
+```csharp
+IIF(expr, truepart, falsepart)
+```
+
+| Arguments | Description |
+|-------------|-------------------------------------------------|
+| `expr` | The expression to evaluate. |
+| `truepart` | The value to return if the expression is true. |
+| `falsepart` | The value to return if the expression is false. |
+
+Example: `myDataColumn.Expression = "IIF(total>1000, 'expensive', 'dear')`
+
+### `TRIM`
+
+This function removes all leading and trailing blank characters like \r, \n, \t, and ' '.
+
+```csharp
+TRIM(expression)
+```
+
+| Argument | Description |
+|--------------|-------------------------|
+| `expression` | The expression to trim. |
+
+### `SUBSTRING`
+
+This function gets a substring of a specified length, starting at a specified point in the string.
+
+```csharp
+SUBSTRING(expression, start, length)
+```
+
+| Argument | Description |
+|--------------|-----------------------------------------------------|
+| `expression` | The source string for the substring |
+| `start` | Integer that specifies where the substring starts. |
+| `length` | Integer that specifies the length of the substring. |
+
+Example: `myDataColumn.Expression = "SUBSTRING(phone, 7, 8)"`
+
+> [!NOTE]
+> You can reset the property by assigning it a null value or empty string. If a default value is set on the expression column, all previously filled rows are assigned the default value after the property is reset.
+
+ ]]>
+
. The second and third columns contain expressions; the second calculates tax using a variable tax rate, and the third adds the result of the calculation to the value of the first column. The resulting table is displayed in a control.
diff --git a/xml/System.Data/DataSet.xml b/xml/System.Data/DataSet.xml
index 70697d72870..25f8ea69a3f 100644
--- a/xml/System.Data/DataSet.xml
+++ b/xml/System.Data/DataSet.xml
@@ -91,7 +91,41 @@
Represents an in-memory cache of data.
- For more information about this API, see Supplemental API remarks for DataSet.
+
+ class, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The consists of a collection of objects that you can relate to each other with objects. You can also enforce data integrity in the by using the and objects. For further details about working with objects, see [DataSets, DataTables, and DataViews](/dotnet/framework/data/adonet/dataset-datatable-dataview/index).
+
+Whereas objects contain the data, the allows you to navigate though the table hierarchy. The tables are contained in a accessed through the property. When accessing objects, note that they are conditionally case sensitive. For example, if one is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. For more information about working with objects, see [Creating a DataTable](/dotnet/framework/data/adonet/dataset-datatable-dataview/creating-a-datatable).
+
+A can read and write data and schema as XML documents. The data and schema can then be transported across HTTP and used by any application, on any platform that is XML-enabled. You can save the schema as an XML schema with the method, and both schema and data can be saved using the method. To read an XML document that includes both schema and data, use the method.
+
+In a typical multiple-tier implementation, the steps for creating and refreshing a , and in turn, updating the original data are to:
+
+1. Build and fill each in a with data from a data source using a .
+
+2. Change the data in individual objects by adding, updating, or deleting objects.
+
+3. Invoke the method to create a second that features only the changes to the data.
+
+4. Call the method of the , passing the second as an argument.
+
+5. Invoke the method to merge the changes from the second into the first.
+
+6. Invoke the on the . Alternatively, invoke to cancel the changes.
+
+> [!NOTE]
+> The and objects inherit from , and support the interface for remoting. These are the only ADO.NET objects that can be remoted.
+
+> [!NOTE]
+> Classes inherited from are not finalized by the garbage collector, because the finalizer has been suppressed in . The derived class can call the method in its constructor to allow the class to be finalized by the garbage collector.
+
+## Security considerations
+
+For information about DataSet and DataTable security, see [Security guidance](/dotnet/framework/data/adonet/dataset-datatable-dataview/security-guidance).
+
+ ]]>
+
from the **Northwind** database.
diff --git a/xml/System.Data/DataTable.xml b/xml/System.Data/DataTable.xml
index 49fdc7847dc..d2b5a1c9b95 100644
--- a/xml/System.Data/DataTable.xml
+++ b/xml/System.Data/DataTable.xml
@@ -102,7 +102,44 @@
Represents one table of in-memory data.
- For more information about this API, see Supplemental API remarks for DataTable.
+
+ class is a central object in the ADO.NET library. Other objects that use include the and the .
+
+ object names are conditionally case sensitive. For example, if one is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. A can contain two objects that have the same property value but different property values. For more information about working with objects, see [Creating a DataTable](/dotnet/framework/data/adonet/dataset-datatable-dataview/creating-a-datatable).
+
+If you're creating a programmatically, you must first define its schema by adding objects to the (accessed through the property). For more information about adding objects, see [Adding Columns to a DataTable](/dotnet/framework/data/adonet/dataset-datatable-dataview/adding-columns-to-a-datatable).
+
+To add rows to a , you must first use the method to return a new object. The method returns a row with the schema of the , as it is defined by the table's . The maximum number of rows that a can store is 16,777,216. For more information, see [Adding Data to a DataTable](/dotnet/framework/data/adonet/dataset-datatable-dataview/adding-data-to-a-datatable).
+
+The also contains a collection of objects that can be used to ensure the integrity of the data. For more information, see [DataTable Constraints](/dotnet/framework/data/adonet/dataset-datatable-dataview/datatable-constraints).
+
+There are many events that can be used to determine when changes are made to a table. These include , , , and . For more information about the events that can be used with a , see [Handling DataTable Events](/dotnet/framework/data/adonet/dataset-datatable-dataview/handling-datatable-events).
+
+When an instance of is created, some of the read/write properties are set to initial values. For a list of these values, see the constructor.
+
+> [!NOTE]
+> The and objects inherit from and support the interface for .NET remoting. These are the only ADO.NET objects that you can use for .NET remoting.
+
+## Security considerations
+
+For information about DataSet and DataTable security, see [Security guidance](/dotnet/framework/data/adonet/dataset-datatable-dataview/security-guidance).
+
+## Examples
+
+This sample demonstrates how to create a DataTable manually with specific schema definitions:
+
+- Create multiple DataTables and define the initial columns.
+- Create the table constraints.
+- Insert the values and display the tables.
+- Create the expression columns and display the tables.
+
+:::code language="csharp" source="./snippets/System.Data/DataTable/Overview/cs/source.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Data/DataTable/Overview/source.vb" id="Snippet1":::
+
+ ]]>
+
objects and one object, and adds the new objects to a . The tables are then displayed in a control.
diff --git a/xml/System.Diagnostics.Tracing/EventSource.xml b/xml/System.Diagnostics.Tracing/EventSource.xml
index a6e7123e7ba..167660940f7 100644
--- a/xml/System.Diagnostics.Tracing/EventSource.xml
+++ b/xml/System.Diagnostics.Tracing/EventSource.xml
@@ -65,7 +65,74 @@
Provides the ability to create events for event tracing across platforms.
- For more information about this API, see Supplemental API remarks for EventSource.
+
+ class is intended to be inherited by a user class that provides specific events to be used for event tracing. The methods are called to log the events.
+
+The basic functionality of is sufficient for most applications. If you want more control over the event metadata that's created, you can apply the attribute to the methods. For advanced event source applications, it is possible to intercept the commands being sent to the derived event source and change the filtering, or to cause actions (such as dumping a data structure) to be performed by the inheritor. An event source can be activated in-process using and out-of-process using EventPipe-based tools such as `dotnet-trace` or Event Tracing for Windows (ETW) based tools like `PerfView` or `Logman`. It is also possible to programmatically control and intercept the data dispatcher. The class provides additional functionality.
+
+## Conventions
+
+-derived classes should follow the following conventions:
+
+- User-defined classes should implement a singleton pattern. The singleton instance is traditionally named `Log`. By extension, users should not call `IDisposable.Dispose` manually and allow the runtime to clean up the singleton instance at the end of managed code execution.
+- A user-defined, derived class should be marked as `sealed` unless it implements the advanced "Utility EventSource" configuration discussed in the Advanced Usage section.
+- Call before performing any resource intensive work related to firing an event.
+- You can implicitly create objects by declaring two event methods with subsequent event IDs that have the naming pattern `Start` and `Stop`. These events _must_ be declared next to each other in the class definition and the `Start` method _must_ come first.
+- Attempt to keep objects backwards compatible and version them appropriately. The default version for an event is `0`. The version can be can be changed by setting . Change the version of an event whenever you change properties of the payload. Always add new payload properties to the end of the event declaration. If this is not possible, create a new event with a new ID to replace the old one.
+- When declaring event methods, specify fixed-size payload properties before variably sized properties.
+- are used as a bit mask for specifying specific events when subscribing to a provider. You can specify keywords by defining a `public static class Keywords` member class that has `public const EventKeywords` members.
+- Associate expensive events with an using . This pattern allows users of your to opt out of these expensive operations.
+
+## Self-describing (tracelogging) vs. manifest event formats
+
+ can be configured into to two different modes based on the constructor used or what flags are set on .
+
+Historically, these two formats are derived from two formats that Event Tracing for Windows (ETW) used. While these two modes don't affect your ability to use Event Tracing for Windows (ETW) or EventPipe-based listeners, they do generate the metadata for events differently.
+
+The default event format is , which is set if not specified on . Manifest-based objects generate an XML document representing the events defined on the class upon initialization. This requires the to reflect over itself to generate the provider and event metadata.
+
+To use self-describing (tracelogging) event format, construct your using the constructor, the constructor, or by setting the `EtwSelfDescribingEventFormat` flag on . Self-describing sources generate minimal provider metadata on initialization and only generate event metadata when is called. Unlike the manifest-based format, when listening via ETW only the Level, Keyword, and Opcode metadata are included from the attribute. Other properties such as EventId or Message are not included.
+
+In practice, these event format settings only affect usage with readers based on Event Tracing for Windows (ETW). They can, however, have a small effect on initialization time and per-event write times due to the time required for reflection and generating the metadata.
+
+## Examples
+
+The following example shows a simple implementation of the class.
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program.vb" id="Snippet1":::
+
+The following example shows a more complex implementation of the class.
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program1.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics.Tracing/EventSource/Overview/program1.vb" id="Snippet1":::
+
+## Advanced usage
+
+Traditionally, user-defined objects expect to inherit directly from . For advanced scenarios, however, you can create `abstract` objects, called _Utility Sources_, and implement interfaces. Using one or both of these techniques allows you to share code between different derived sources.
+
+> [!IMPORTANT]
+> Abstract objects cannot define keywords, tasks, opcodes, channels, or events.
+
+> [!IMPORTANT]
+> To avoid name collisions at runtime when generating event metadata, don't explicitly implement interface methods when using interfaces with .
+
+The following example shows an implementation of that uses an interface.
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs" id="InterfaceSource":::
+
+The following example shows an implementation of that uses the Utility EventSource pattern.
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs" id="UtilitySource":::
+
+The following example shows an implementation of for tracing information about a component in a library.
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program2.cs" id="ComplexSource":::
+
+ ]]>
+
This type is thread safe.
diff --git a/xml/System.Diagnostics.Tracing/EventWrittenEventArgs.xml b/xml/System.Diagnostics.Tracing/EventWrittenEventArgs.xml
index 818b48b7dce..2dff2850d5a 100644
--- a/xml/System.Diagnostics.Tracing/EventWrittenEventArgs.xml
+++ b/xml/System.Diagnostics.Tracing/EventWrittenEventArgs.xml
@@ -53,7 +53,29 @@
Provides data for the callback.
- For more information about this API, see Supplemental API remarks for EventWrittenEventArgs.
+
+ class provides data for the callback.
+
+Whenever an event is dispatched to an , the callback method is invoked. It is passed an `EventWrittenEventArgs` instance that contains information associated with the event. All property values of the `EventWrittenEventArgs` class are valid only during the callback.
+
+The following sections contain additional information about individual `EventWrittenEventArgs` properties.
+
+## ActivityId property
+
+When using and its derived classes, threads can be marked as having an activity associated with them. The `ActivityId` property returns the activity ID of the thread that logged the event. Note that threads do not have to have an activity, in which case this property returns .
+
+## OSThreadId and TimeStamp properties
+
+Starting with .NET Core 2.2, objects can subscribe to native runtime events (such as GC, JIT, and threadpool events) in addition to events emitted by objects. In previous versions of .NET Core and all versions of .NET Framework, the thread ID and timestamp can be gathered from the environment, because they are dispatched synchronously on the same thread that emitted them. Not all native runtime events can be dispatched synchronously, however. Some events, such as GC events, are emitted when managed thread execution is suspended. These events are buffered in native code and are dispatched by a dispatcher thread once managed code can execute again. Because these events are buffered, the environment cannot be used to reliably retrieve the thread ID and timestamp. Because of this, starting with .NET Core 2.2, thread ID and timestamp information are available as members of the `EventWrittenEventArgs` class.
+
+## RelatedActivityId property
+
+A related activity is an activity that is strongly related to the current one. Typically, it is either the activity that caused the current activity (events with the `Start` opcode typically do this) or an activity that was created by the current one (events with the `Send` opcode typically do this). When it is used, the `RelatedActivityID` is explicitly passed by the method doing the logging. Many events don't pass a `RelatedActivityId`, in which case this property returns .
+
+ ]]>
+
diff --git a/xml/System.Diagnostics/PerformanceCounterType.xml b/xml/System.Diagnostics/PerformanceCounterType.xml
index 400db6ee222..55bf38a10cb 100644
--- a/xml/System.Diagnostics/PerformanceCounterType.xml
+++ b/xml/System.Diagnostics/PerformanceCounterType.xml
@@ -32,7 +32,140 @@
Specifies performance counter types that map directly to native types.
- For more information about this API, see Supplemental API remarks for PerformanceCounterType.
+
+ enumeration specifies performance counter types that map directly to native types.
+
+Some counter types represent raw data, while others represent calculated values that are based on one or more counter samples. The following categories classify the types of counters available.
+
+- **Average**: Measures a value over time and displays the average of the last two measurements. A base counter that tracks the number of samples involved is associated with each average counter.
+- **Difference**: Subtracts the last measurement from the previous one and, if the difference is positive, displays it; if negative, displays a zero.
+- **Instantaneous**: Displays the most recent measurement.
+- **Percentage**: Displays calculated values as a percentage.
+- **Rate**: Samples an increasing count of events over time and divides the change in count values by the change in time to display a rate of activity.
+
+When sampling performance counter data, using a counter type that represents an average can make raw data values meaningful for your use. For example, the raw data counter `NumberOfItems64` can expose data that is fairly random from sample to sample. The formula for an average calculation of the values that the counter returns would be (X 0 +X 1 +…+X n)/n, where each X i is a raw counter sample.
+
+Rate counters are similar to average counters, but more useful for situations in which the rate increases as a resource is used. A formula that quickly calculates the average is ((X n -X 0)/(T n -T 0)) / frequency, where each X i is a counter sample and each T i is the time that the corresponding sample was taken. The result is the average usage per second.
+
+*Multitimer counters* collect data from more than one instance of a component, such as a processor or disk.
+
+*Inverse counters* measure the time that a component is not active and derive the active time from that measurement.
+
+> [!NOTE]
+> Unless otherwise indicated, the time base is seconds.
+
+When instrumenting applications (creating and writing custom performance counters), you might be working with performance counter types that rely on an accompanying base counter that is used in the calculations. The base counter must be immediately after its associated counter in the collection your application uses. The following table lists the base counter types with their corresponding performance counter types.
+
+| Base counter type | Performance counter types |
+|--------------------|----------------------------------------------|
+| `AverageBase` | `AverageTimer32`
`AverageCount64` |
+| `RawBase` | `RawFraction` |
+| `CounterMultiBase` | `CounterMultiTimer`
`CounterMultiTimerInverse`
`CounterMultiTimer100Ns`
`CounterMultiTimer100NsInverse`|
+| `SampleBase` | `SampleFraction` |
+
+The following are the formulas used by some of the counters that represent calculated values:
+
+- `AverageCount64`: (N1 - N0)/(B1 - B0), where N 1 and N 0 are performance counter readings, and B1 and B0 are their corresponding `AverageBase` values. Thus, the numerator represents the numbers of items processed during the sample interval, and the denominator represents the number of operations completed during the sample interval.
+
+- `AverageTimer32`: ((N1 - N0)/F)/(B1 - B0), where N1 and N0 are performance counter readings, B1 and B0 are their corresponding `AverageBase` values, and F is the number of ticks per second. The value of F is factored into the equation so that the result can be displayed in seconds. Thus, the numerator represents the numbers of ticks counted during the last sample interval, F represents the frequency of the ticks, and the denominator represents the number of operations completed during the last sample interval.
+
+- `CounterDelta32`: N1 - N0, where N1 and N0 are performance counter readings.
+
+- `CounterDelta64`: N1 - N0, where N1 and N0 are performance counter readings.
+
+- `CounterMultiTimer`: ((N1 - N0) / (D1 - D0)) x 100 / B, where N1 and N0 are performance counter readings, D1 and D0 are their corresponding time readings in ticks of the system performance timer, and the variable B denotes the base count for the monitored components (using a base counter of type `CounterMultiBase`). Thus, the numerator represents the portions of the sample interval during which the monitored components were active, and the denominator represents the total elapsed time of the sample interval.
+
+- `CounterMultiTimer100Ns`: ((N1 - N0) / (D1 - D0)) x 100 / B, where N1 and N0 are performance counter readings, D1 and D0 are their corresponding time readings in 100-nanosecond units, and the variable B denotes the base count for the monitored components (using a base counter of type `CounterMultiBase`). Thus, the numerator represents the portions of the sample interval during which the monitored components were active, and the denominator represents the total elapsed time of the sample interval.
+
+- `CounterMultiTimer100NsInverse`: (B - ((N1 - N0) / (D1 - D0))) x 100, where the denominator represents the total elapsed time of the sample interval, the numerator represents the time during the interval when monitored components were inactive, and B represents the number of components being monitored, using a base counter of type `CounterMultiBase`.
+
+- `CounterMultiTimerInverse`: (B- ((N1 - N0) / (D1 - D0))) x 100, where the denominator represents the total elapsed time of the sample interval, the numerator represents the time during the interval when monitored components were inactive, and B represents the number of components being monitored, using a base counter of type `CounterMultiBase`.
+
+- `CounterTimer`: (N1 - N0) / (D1 - D0), where N1 and N0 are performance counter readings, and D1 and D0 are their corresponding time readings. Thus, the numerator represents the portions of the sample interval during which the monitored components were active, and the denominator represents the total elapsed time of the sample interval.
+
+- `CounterTimerInverse`: (1- ((N1 - N0) / (D1 - D0))) x 100, where the numerator represents the time during the interval when the monitored components were inactive, and the denominator represents the total elapsed time of the sample interval.
+
+- `CountPerTimeInterval32`: (N1 - N0) / (D1 - D0), where the numerator represents the number of items in the queue, and the denominator represents the time elapsed during the last sample interval.
+
+- `CountPerTimeInterval64`: (N1 - N0) / (D1 - D0), where the numerator represents the number of items in a queue and the denominator represents the time elapsed during the sample interval.
+
+- `ElapsedTime`: (D0 - N0) / F, where D0 represents the current time, N0 represents the time the object was started, and F represents the number of time units that elapse in one second. The value of F is factored into the equation so that the result can be displayed in seconds.
+
+- `NumberOfItems32`: None. Does not display an average, but shows the raw data as it is collected.
+
+- `NumberOfItems64`: None. Does not display an average, but shows the raw data as it is collected.
+
+- `NumberOfItemsHEX32`: None. Does not display an average, but shows the raw data as it is collected.
+
+- `NumberOfItemsHEX64`: None. Does not display an average, but shows the raw data as it is collected
+
+- `RateOfCountsPerSecond32`: (N1 - N0) / ((D1 - D0) / F), where N1 and N0 are performance counter readings, D1 and D0 are their corresponding time readings, and F represents the number of ticks per second. Thus, the numerator represents the number of operations performed during the last sample interval, the denominator represents the number of ticks elapsed during the last sample interval, and F is the frequency of the ticks. The value of F is factored into the equation so that the result can be displayed in seconds.
+
+- `RateOfCountsPerSecond64`: (N1 - N0) / ((D1 - D0) / F), where N1 and N0 are performance counter readings, D1 and D0 are their corresponding time readings, and F represents the number of ticks per second. Thus, the numerator represents the number of operations performed during the last sample interval, the denominator represents the number of ticks elapsed during the last sample interval, and F is the frequency of the ticks. The value of F is factored into the equation so that the result can be displayed in seconds.
+
+- `RawFraction`: (N0 / D0) x 100, where D0 represents a measured attribute (using a base counter of type `RawBase`) and N0 represents one component of that attribute.
+
+- `SampleCounter`: (N1 - N0) / ((D1 - D0) / F), where the numerator (N) represents the number of operations completed, the denominator (D) represents elapsed time in units of ticks of the system performance timer, and F represents the number of ticks that elapse in one second. F is factored into the equation so that the result can be displayed in seconds.
+
+- `SampleFraction`: ((N1 - N0) / (D1 - D0)) x 100, where the numerator represents the number of successful operations during the last sample interval, and the denominator represents the change in the number of all operations (of the type measured) completed during the sample interval, using counters of type `SampleBase`.
+
+- `Timer100Ns`: (N1 - N0) / (D1 - D0) x 100, where the numerator represents the portions of the sample interval during which the monitored components were active, and the denominator represents the total elapsed time of the sample interval.
+
+- `Timer100NsInverse`: (1- ((N1 - N0) / (D1 - D0))) x 100, where the numerator represents the time during the interval when the monitored components were inactive, and the denominator represents the total elapsed time of the sample interval.
+
+## Examples
+
+The following examples demonstrate several of the counter types in the enumeration.
+
+### AverageCount64
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/CounterCreationData/Overview/averagecount32.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagecount32.vb" id="Snippet1":::
+
+### AverageTimer32
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.cs" id="Snippet2":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/averagetimer32.vb" id="Snippet2":::
+
+### ElapsedTime
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounter/NextValue/elapsedtime.cs" id="Snippet2":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/elapsedtime.vb" id="Snippet2":::
+
+### NumberOfItems32
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems32.vb" id="Snippet1":::
+
+### NumberOfItems64
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/numberofitems64.vb" id="Snippet1":::
+
+### SampleFraction
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/program.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/program.vb" id="Snippet1":::
+
+### RateOfCountsPerSecond32
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond32.vb" id="Snippet1":::
+
+### RateOfCountsPerSecond64
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rateofcountspersecond64.vb" id="Snippet1":::
+
+### RawFraction
+
+:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Diagnostics/PerformanceCounterType/Overview/rawfraction.vb" id="Snippet1":::
+
+ ]]>
+
diff --git a/xml/System.Diagnostics/ProcessStartInfo.xml b/xml/System.Diagnostics/ProcessStartInfo.xml
index b2e64d946c8..2d3c2005b3a 100644
--- a/xml/System.Diagnostics/ProcessStartInfo.xml
+++ b/xml/System.Diagnostics/ProcessStartInfo.xml
@@ -1750,7 +1750,31 @@ You can use asynchronous read operations to avoid these dependencies and their d
Gets or sets a value indicating whether to use the operating system shell to start the process.
if the shell should be used when starting the process; if the process should be created directly from the executable file. The default is (or on .NET Framework apps).
- For more information about this API, see Supplemental API remarks for ProcessStartInfo.UseShellExecute.
+
+ class specifies a set of values that are used when you start a process.
+
+Setting the property to `false` enables you to redirect input, output, and error streams.
+
+The word "shell" in this context (`UseShellExecute`) refers to a graphical shell (similar to the Windows shell) rather than command shells (for example, `bash` or `sh`) and lets users launch graphical applications or open documents.
+
+> [!NOTE]
+> must be `false` if the property is not `null` or an empty string, or an will be thrown when the method is called.
+
+When you use the operating system shell to start processes, you can start any document (which is any registered file type associated with an executable that has a default open action) and perform operations on the file, such as printing, by using the object. When is `false`, you can start only executables by using the object.
+
+> [!NOTE]
+> must be `true` if you set the property to `true`.
+
+## WorkingDirectory
+
+The property behaves differently depending on the value of the property. When is `true`, the property specifies the location of the executable. If is an empty string, it's assumed that the current directory contains the executable.
+
+When is `false`, the property is not used to find the executable. Instead, it is used only by the process that is started and has meaning only within the context of the new process. When is `false`, the property can be either a fully qualified path to the executable, or a simple executable name that the system will attempt to find within folders specified by the `PATH` environment variable. The interpretation of the search path depends on the operating system. For more information, enter [`HELP PATH`](/windows-server/administration/windows-commands/path) or [`man sh`](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03) at a command prompt.
+
+ ]]>
+
Encapsulates a 3-by-3 affine matrix that represents a geometric transform. This class cannot be inherited.
- For more information about this API, see Supplemental API remarks for Matrix.
+
+ class encapsulates a 3-by-3 affine matrix that represents a geometric transform.
+
+In GDI+, you can store an affine transformation in a object. Because the third column of a matrix that represents an affine transformation is always (0, 0, 1), you specify only the six numbers in the first two columns when you construct a object. The statement `Matrix myMatrix = new Matrix(0, 1, -1, 0, 3, 4)` constructs the matrix shown in the following figure.
+
+
+
+[!INCLUDE[System.Drawing.Common note](./includes/system-drawing-common.md)]
+
+## Composite transformations
+
+A composite transformation is a sequence of transformations, one followed by the other. Consider the matrices and transformations in the following list:
+
+| Matrix | Transformation |
+|----------|-------------------------------------------|
+| Matrix A | Rotate 90 degrees |
+| Matrix B | Scale by a factor of 2 in the x direction |
+| Matrix C | Translate 3 units in the y direction |
+
+If you start with the point (2, 1) - represented by the matrix [2 1 1] - and multiply by A, then B, then C, the point (2, 1) will undergo the three transformations in the order listed.
+
+`[2 1 1]ABC = [-2 5 1]`
+
+Rather than store the three parts of the composite transformation in three separate matrices, you can multiply A, B, and C together to get a single 3×3 matrix that stores the entire composite transformation. Suppose `ABC = D`. Then a point multiplied by D gives the same result as a point multiplied by A, then B, then C.
+
+`[2 1 1]D = [-2 5 1]`
+
+The following illustration shows the matrices A, B, C, and D.
+
+
+
+The fact that the matrix of a composite transformation can be formed by multiplying the individual transformation matrices means that any sequence of affine transformations can be stored in a single object.
+
+> [!CAUTION]
+> The order of a composite transformation is important. In general, rotate, then scale, then translate is not the same as scale, then rotate, then translate. Similarly, the order of matrix multiplication is important. In general, ABC is not the same as BAC.
+
+The class provides several methods for building a composite transformation: , , , , , and . The following example creates the matrix of a composite transformation that first rotates 30 degrees, then scales by a factor of 2 in the y direction, and then translates 5 units in the x direction:
+
+:::code language="csharp" source="~/snippets/csharp/System.Drawing.Drawing2D/Matrix/Overview/Class1.cs" id="Snippet11":::
+:::code language="vb" source="~/snippets/visualbasic/System.Drawing.Drawing2D/Matrix/Overview/Class1.vb" id="Snippet11":::
+
+ ]]>
+
Coordinate Systems and Transformations
diff --git a/xml/System.Dynamic/ExpandoObject.xml b/xml/System.Dynamic/ExpandoObject.xml
index 5944d23d6a4..692ccd1726e 100644
--- a/xml/System.Dynamic/ExpandoObject.xml
+++ b/xml/System.Dynamic/ExpandoObject.xml
@@ -85,7 +85,133 @@
Represents an object whose members can be dynamically added and removed at run time.
- For more information about this API, see Supplemental API remarks for ExpandoObject.
+
+ class enables you to add and delete members of its instances at runtime and also to set and get values of these members. This class supports dynamic binding, which enables you to use standard syntax like `sampleObject.sampleMember` instead of more complex syntax like `sampleObject.GetAttribute("sampleMember")`.
+
+The `ExpandoObject` class implements the standard Dynamic Language Runtime (DLR) interface , which enables you to share instances of the `ExpandoObject` class between languages that support the DLR interoperability model. For example, you can create an instance of the `ExpandoObject` class in C# and then pass it to an IronPython function. For more information, see [Dynamic Language Runtime Overview](/dotnet/framework/reflection-and-codedom/dynamic-language-runtime-overview) and [Introducing the ExpandoObject](/archive/blogs/csharpfaq/dynamic-in-c-4-0-introducing-the-expandoobject).
+
+The `ExpandoObject` class is an implementation of the dynamic object concept that enables getting, setting, and invoking members. If you want to define types that have their own dynamic dispatch semantics, use the class. If you want to define how dynamic objects participate in the interoperability protocol and manage DLR fast dynamic dispatch caching, create your own implementation of the interface.
+
+## Create an instance
+
+In C#, to enable late binding for an instance of the `ExpandoObject` class, you must use the `dynamic` keyword. For more information, see [Using Type dynamic](/dotnet/csharp/programming-guide/types/using-type-dynamic).
+
+In Visual Basic, dynamic operations are supported by late binding. For more information, see [Early and Late Binding (Visual Basic)](/dotnet/visual-basic/programming-guide/language-features/early-late-binding/index).
+
+The following code example demonstrates how to create an instance of the `ExpandoObject` class.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet1":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet1":::
+
+## Add new members
+
+You can add properties, methods, and events to instances of the `ExpandoObject` class.
+
+The following code example demonstrates how to add a new property to an instance of the `ExpandoObject` class.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet2":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet2":::
+
+The methods represent lambda expressions that are stored as delegates, which can be invoked when they are needed. The following code example demonstrates how to add a method that increments a value of the dynamic property.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet3":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet3":::
+
+The following code example demonstrates how to add an event to an instance of the `ExpandoObject` class.
+
+```csharp
+class Program
+{
+ static void Main(string[] args)
+ {
+ dynamic sampleObject = new ExpandoObject();
+
+ // Create a new event and initialize it with null.
+ sampleObject.sampleEvent = null;
+
+ // Add an event handler.
+ sampleObject.sampleEvent += new EventHandler(SampleHandler);
+
+ // Raise an event for testing purposes.
+ sampleObject.sampleEvent(sampleObject, new EventArgs());
+ }
+
+ // Event handler.
+ static void SampleHandler(object sender, EventArgs e)
+ {
+ Console.WriteLine("SampleHandler for {0} event", sender);
+ }
+}
+// This code example produces the following output:
+// SampleHandler for System.Dynamic.ExpandoObject event.
+```
+
+```vb
+Module Module1
+
+Sub Main()
+ Dim sampleObject As Object = New ExpandoObject()
+
+ ' Create a new event and initialize it with null.
+ sampleObject.sampleEvent = Nothing
+
+ ' Add an event handler.
+ Dim handler As EventHandler = AddressOf SampleHandler
+ sampleObject.sampleEvent =
+ [Delegate].Combine(sampleObject.sampleEvent, handler)
+
+ ' Raise an event for testing purposes.
+ sampleObject.sampleEvent.Invoke(sampleObject, New EventArgs())
+
+End Sub
+
+' Event handler.
+Sub SampleHandler(ByVal sender As Object, ByVal e As EventArgs)
+ Console.WriteLine("SampleHandler for {0} event", sender)
+End Sub
+
+' This code example produces the following output:
+' SampleHandler for System.Dynamic.ExpandoObject event.
+
+End Module
+```
+
+## Pass as a parameter
+
+You can pass instances of the `ExpandoObject` class as parameters. Note that these instances are treated as dynamic objects in C# and late-bound objects in Visual Basic. This means that you do not have IntelliSense for object members and you do not receive compiler errors when you call non-existent members. If you call a member that does not exist, an exception occurs.
+
+The following code example demonstrates how you can create and use a method to print the names and values of properties.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet4":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet4":::
+
+## Enumerate and delete members
+
+The `ExpandoObject` class implements the `IDictionary` interface. This enables enumeration of members added to the instance of the `ExpandoObject` class at runtime. This can be useful if you do not know at compile time what members an instance might have.
+
+The following code example shows how you can cast an instance of the `ExpandoObject` class to the interface and enumerate the instance's members.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet5":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet5":::
+
+In languages that do not have syntax for deleting members (such as C# and Visual Basic), you can delete a member by implicitly casting an instance of the `ExpandoObject` to the `IDictionary` interface and then deleting the member as a key/value pair. This is shown in the following example.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet6":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet6":::
+
+## Receive notifications of property changes
+
+The `ExpandoObject` class implements the interface and can raise a event when a member is added, deleted, or modified. This enables `ExpandoObject` class integration with Windows Presentation Foundation (WPF) data binding and other environments that require notification about changes in the object content.
+
+The following code example demonstrates how to create an event handler for the `PropertyChanged` event.
+
+:::code language="csharp" source="~/snippets/csharp/System.Dynamic/ExpandoObject/Overview/program.cs" id="Snippet7":::
+:::code language="vb" source="~/snippets/visualbasic/System.Dynamic/ExpandoObject/Overview/module1.vb" id="Snippet7":::
+
+ ]]>
+