Condividi tramite


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

Definizione

Scrive un evento che indica che l'attività corrente è correlata a un'altra attività.

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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
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
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")>]
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())

Parametri

eventId
Int32

Identificatore che identifica in modo univoco questo evento all'interno di EventSource.

relatedActivityIdchildActivityID
Guid

Identificatore di attività correlato.

args
Object[]

Matrice di oggetti che contengono dati sull'evento.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come specificare un'origine evento che chiama WriteEventWithRelatedActivityId.

[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);
            }
        }
    }

Commenti

Il WriteEventWithRelatedActivityId metodo registra un evento di trasferimento. L'attività del thread corrente viene registrata con l'evento e in questo modo due attività possono essere correlate da un consumer di eventi.

Il metodo di evento ETW che chiama questa funzione deve seguire queste linee guida:

Se args non viene usato, viene convertito in una matrice vuota per la chiamata risultante a ETW.

Si applica a