Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use custom event to get start and stop duration
using Microsoft.Diagnostics.Tracing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ETWSamples
public sealed class CustomEvent: EventSource
public static CustomEvent Instance = new CustomEvent();
[Event(1, Opcode = EventOpcode.Start)]
public void RequestStart(int RequestID ) { WriteEvent(1, RequestID ); }
[Event(2, Opcode = EventOpcode.Stop)]
public void RequestStop(int RequestID) { WriteEvent(2, RequestID); }
/// <summary>
/// With this perfview would show the duration it took to complete an event based on the
/// naming convention.
/// This could also be used for stopping perfview when the duration of this took more than what
/// is expected.
/// </summary>
public static void Run()
for (int i = 1; i < 12; i++)
if ((i % 2) == 0) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment