TimeMeasureProfiler<TResult> Class
Definition
- Namespace
- Cuemon.Diagnostics
- Assemblies
- Cuemon.Diagnostics.dll
Represents a profiler that is optimized for time measuring operations that provides a return value. This class cannot be inherited.
public sealed class TimeMeasureProfiler<TResult> : TimeMeasureProfiler
Type Parameters
TResultThe type of the return value.
- Inheritance
-
TimeMeasureProfiler<TResult>
- Inherited Members
Examples
TimeMeasureProfiler<TResult> extends TimeMeasureProfiler by providing typed access to the result of a timed function via TimeMeasure.WithFunc. This example wraps a Thread.Sleep(100) followed by returning 42, then inspects the profiler's Result (42), Elapsed (~100ms), IsRunning (False), and Member properties. Key setup includes capturing the profiler and checking each property after execution. Console output shows the result value, the elapsed duration, the running state, the compiler-generated lambda member name, and the ToString() output showing the member name and elapsed time.
// Program.cs
using System;
using System.Threading;
using Cuemon.Diagnostics;
using MyApp.Examples;
new TimeMeasureProfilerOfTExample().Demonstrate();
namespace MyApp.Examples
{
public class TimeMeasureProfilerOfTExample
{
public void Demonstrate()
{
// TimeMeasure.WithFunc returns a TimeMeasureProfiler<int>
TimeMeasureProfiler<int> profiler = TimeMeasure.WithFunc(() =>
{
Thread.Sleep(100);
return 42;
});
Console.WriteLine($"Result: {profiler.Result}"); // 42
Console.WriteLine($"Elapsed: {profiler.Elapsed}"); // ~00:00:00.100
Console.WriteLine($"IsRunning: {profiler.IsRunning}"); // False
Console.WriteLine($"Member: {profiler.Member}"); // MyApp.Examples.TimeMeasureProfilerOfTExample+<>c.<Demonstrate>b__0_0()
Console.WriteLine(profiler.ToString());
// Output: MyApp.Examples.TimeMeasureProfilerOfTExample+<>c.<Demonstrate>b__0_0() took ~00:00:00.100 to execute.
}
}
}
Properties
| Name | Description |
|---|---|
| Result | Gets or sets the result of a time measuring operation that returned a value. |