[Event(1)]
internal void MathResult(int x, int y, int z, string formula) { this.WriteEvent(1, x, y, z, formula); }
+
+ [Event(2)]
+ internal void DateTimeEvent(DateTime dateTime) => WriteEvent(2, dateTime);
+
+
+ [NonEvent]
+ private unsafe void WriteEvent(int eventId, DateTime dateTime)
+ {
+ EventData* desc = stackalloc EventData[1];
+ long fileTime = dateTime.ToFileTimeUtc();
+ desc[0].DataPointer = (IntPtr)(&fileTime);
+ desc[0].Size = 8;
+ WriteEventCore(eventId, 1, desc);
+ }
}
internal sealed class SimpleEventListener : EventListener
private readonly EventLevel _level;
public int EventCount { get; private set; } = 0;
+ public DateTime DateObserved { get; private set; } = DateTime.MinValue;
public SimpleEventListener(string targetSourceName, EventLevel level)
{
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
- EventCount++;
+ if (eventData.EventId == 2)
+ {
+ DateObserved = (DateTime)eventData.Payload[0];
+ }
+ else
+ EventCount++;
}
}
class EventPipeSmoke
{
private static int messageIterations = 100;
+ private static readonly DateTime ThePast = DateTime.UtcNow;
static int Main(string[] args)
{
eventSource.MathResult(x, y, x+y, formula);
}
+ eventSource.DateTimeEvent(ThePast);
Console.WriteLine("\tEnd: Messaging.\n");
Console.WriteLine($"\tEventListener received {listener.EventCount} event(s)\n");
- pass = listener.EventCount == messageIterations;
+ Console.WriteLine($"\tEventListener received {listener.DateObserved} vs {ThePast}\n");
+ pass = listener.EventCount == messageIterations && ThePast == listener.DateObserved;
}
return pass ? 100 : -1;