EventSource.WriteEventWithRelatedActivityId(Int32, Guid, Object[]) 方法

定義

寫入表示目前活動與另一個活動有關的事件。

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())

參數

eventId
Int32

可在 EventSource 中唯一識別這個事件的識別項。

relatedActivityIdchildActivityID
Guid

相關的活動識別項。

args
Object[]

包含事件相關資料的物件陣列。

範例

下列程式代碼範例示範如何指定呼叫 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);
            }
        }
    }

備註

方法會 WriteEventWithRelatedActivityId 記錄傳輸事件。 目前線程的活動會與 事件一起記錄,這可讓事件取用者關聯兩個活動。

呼叫此函式的 ETW 事件方法必須遵循下列指導方針:

  1. 將第一個 Guid 參數指定為名為 relatedActivityId

  2. Send指定 或 Receive 做為 EventAttribute.Opcode 屬性。

  3. 呼叫 WriteEventWithRelatedActivityId 傳入事件標識符,後面接著相關的標識符 GUID,後面接著傳遞事件方法的所有參數,順序相同。

如果未 args 使用 ,則會將它轉換成空數位列,以取得對 ETW 的結果呼叫。

適用於