EventSource.WriteEventWithRelatedActivityId(Int32, Guid, Object[]) Metoda

Definicja

Zapisuje zdarzenie wskazujące, że bieżące działanie jest związane z innym działaniem.

protected:
 void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, ... cli::array <System::Object ^> ^ args);
protected:
 void WriteEventWithRelatedActivityId(int eventId, Guid childActivityID, ... cli::array <System::Object ^> ^ args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid relatedActivityId, params object[] args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid relatedActivityId, params object?[] args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid childActivityID, params object[] args);
member this.WriteEventWithRelatedActivityId : int * Guid * obj[] -> unit
member this.WriteEventWithRelatedActivityId : int * Guid * obj[] -> unit
Protected Sub WriteEventWithRelatedActivityId (eventId As Integer, relatedActivityId As Guid, ParamArray args As Object())
Protected Sub WriteEventWithRelatedActivityId (eventId As Integer, childActivityID As Guid, ParamArray args As Object())

Parametry

eventId
Int32

Identyfikator, który jednoznacznie identyfikuje to zdarzenie w obiekcie EventSource.

relatedActivityIdchildActivityID
Guid

Powiązany identyfikator działania.

args
Object[]

Tablica obiektów zawierających dane o zdarzeniu.

Przykłady

Poniższy przykład kodu pokazuje, jak można określić źródło zdarzeń, które wywołuje WriteEventWithRelatedActivityIdmetodę .

[EventSource(Name = "Litware-ProductName-ComponentName")]
public sealed class LitwareComponentNameEventSource : EventSource
{
    [Event(1, Task = Tasks.Request, Opcode = EventOpcode.Send)]
    public void RequestStart(Guid relatedActivityId, int reqId, string url)
    {
        WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url);
    }
}
<EventSource(Name:="Litware-ProductName-ComponentName")> _
Public NotInheritable Class LitwareComponentNameEventSource
    Inherits EventSource
    <[Event](1, Task:=Tasks.Request, Opcode:=EventOpcode.Send)> _
    Public Sub RequestStart(relatedActivityId As Guid, reqId As Integer, url As String)
        WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url)
    End Sub

End Class
[EventSource(Name = "Contoso-ProductName-ComponentName")]
public sealed class CustomizedForPerfEventSource : EventSource
{
    [Event(1, Task = Tasks.Request, Opcode = EventOpcode.Send)]
    public void RequestStart(Guid relatedActivityId, int reqId, string url)
    {
        if (IsEnabled())
            WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url);
    }

    [NonEvent]
    unsafe protected void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId,
                    int arg1, string arg2)
    {
        if (IsEnabled())
        {
            if (arg2 == null) arg2 = string.Empty;
            fixed (char* stringBytes = arg2)
            {
                EventData* descrs = stackalloc EventData[2];
                descrs[0].DataPointer = (IntPtr)(&arg1);
                descrs[0].Size = 4;
                descrs[1].DataPointer = (IntPtr)stringBytes;
                descrs[1].Size = ((arg2.Length + 1) * 2);
                WriteEventWithRelatedActivityIdCore(eventId,
                &relatedActivityId, 2, descrs);
            }
        }
    }

Uwagi

Metoda WriteEventWithRelatedActivityId rejestruje zdarzenie transferu. Działanie bieżącego wątku jest rejestrowane przy użyciu zdarzenia i umożliwia to połączenie dwóch działań przez użytkownika zdarzeń.

Metoda zdarzenia ETW wywołująca tę funkcję musi być zgodna z następującymi wytycznymi:

  1. Określ pierwszy parametr jako nazwany GuidrelatedActivityId.

  2. Określ właściwość Send lub Receive jako EventAttribute.Opcode właściwość.

  3. Wywołaj WriteEventWithRelatedActivityId przekazanie identyfikatora zdarzenia, a następnie identyfikator GUID powiązanego identyfikatora, po którym następuje wszystkie parametry przekazywane przez metodę zdarzenia w tej samej kolejności.

Jeśli args nie jest używany, jest konwertowany na pustą tablicę dla wynikowego wywołania funkcji ETW.

Dotyczy