-
Notifications
You must be signed in to change notification settings - Fork 255
/
SyncAsyncEventArgs.xml
174 lines (173 loc) · 9.13 KB
/
SyncAsyncEventArgs.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<Type Name="SyncAsyncEventArgs" FullName="Azure.SyncAsyncEventArgs">
<TypeSignature Language="C#" Value="public class SyncAsyncEventArgs : EventArgs" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit SyncAsyncEventArgs extends System.EventArgs" />
<TypeSignature Language="DocId" Value="T:Azure.SyncAsyncEventArgs" />
<TypeSignature Language="VB.NET" Value="Public Class SyncAsyncEventArgs
Inherits EventArgs" />
<TypeSignature Language="F#" Value="type SyncAsyncEventArgs = class
 inherit EventArgs" />
<AssemblyInfo>
<AssemblyName>Azure.Core</AssemblyName>
<AssemblyVersion>1.13.0.0</AssemblyVersion>
<AssemblyVersion>1.14.0.0</AssemblyVersion>
<AssemblyVersion>1.15.0.0</AssemblyVersion>
<AssemblyVersion>1.16.0.0</AssemblyVersion>
<AssemblyVersion>1.17.0.0</AssemblyVersion>
<AssemblyVersion>1.18.0.0</AssemblyVersion>
<AssemblyVersion>1.19.0.0</AssemblyVersion>
<AssemblyVersion>1.20.0.0</AssemblyVersion>
<AssemblyVersion>1.21.0.0</AssemblyVersion>
<AssemblyVersion>1.22.0.0</AssemblyVersion>
<AssemblyVersion>1.23.0.0</AssemblyVersion>
<AssemblyVersion>1.24.0.0</AssemblyVersion>
<AssemblyVersion>1.25.0.0</AssemblyVersion>
<AssemblyVersion>1.26.0.0</AssemblyVersion>
<AssemblyVersion>1.27.0.0</AssemblyVersion>
<AssemblyVersion>1.28.0.0</AssemblyVersion>
<AssemblyVersion>1.29.0.0</AssemblyVersion>
<AssemblyVersion>1.30.0.0</AssemblyVersion>
<AssemblyVersion>1.31.0.0</AssemblyVersion>
<AssemblyVersion>1.32.0.0</AssemblyVersion>
<AssemblyVersion>1.33.0.0</AssemblyVersion>
<AssemblyVersion>1.34.0.0</AssemblyVersion>
<AssemblyVersion>1.35.0.0</AssemblyVersion>
<AssemblyVersion>1.36.0.0</AssemblyVersion>
<AssemblyVersion>1.37.0.0</AssemblyVersion>
<AssemblyVersion>1.38.0.0</AssemblyVersion>
<AssemblyVersion>1.39.0.0</AssemblyVersion>
<AssemblyVersion>1.40.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.EventArgs</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
Provides data for <see cref="T:Azure.Core.SyncAsyncEventHandler`1" />
events that can be invoked either synchronously or asynchronously.
</summary>
<remarks>To be added.</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SyncAsyncEventArgs (bool isRunningSynchronously, System.Threading.CancellationToken cancellationToken = default);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(bool isRunningSynchronously, valuetype System.Threading.CancellationToken cancellationToken) cil managed" />
<MemberSignature Language="DocId" Value="M:Azure.SyncAsyncEventArgs.#ctor(System.Boolean,System.Threading.CancellationToken)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (isRunningSynchronously As Boolean, Optional cancellationToken As CancellationToken = Nothing)" />
<MemberSignature Language="F#" Value="new Azure.SyncAsyncEventArgs : bool * System.Threading.CancellationToken -> Azure.SyncAsyncEventArgs" Usage="new Azure.SyncAsyncEventArgs (isRunningSynchronously, cancellationToken)" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.Core</AssemblyName>
<AssemblyVersion>1.40.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="isRunningSynchronously" Type="System.Boolean" />
<Parameter Name="cancellationToken" Type="System.Threading.CancellationToken" />
</Parameters>
<Docs>
<param name="isRunningSynchronously">
A value indicating whether the event handler was invoked
synchronously or asynchronously. Please see
<see cref="T:Azure.Core.SyncAsyncEventHandler`1" /> for more details.
</param>
<param name="cancellationToken">
A cancellation token related to the original operation that raised
the event. It's important for your handler to pass this token
along to any asynchronous or long-running synchronous operations
that take a token so cancellation will correctly propagate. The
default value is <see cref="P:System.Threading.CancellationToken.None" />.
</param>
<summary>
Initializes a new instance of the <see cref="T:Azure.SyncAsyncEventArgs" />
class.
</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="CancellationToken">
<MemberSignature Language="C#" Value="public System.Threading.CancellationToken CancellationToken { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Threading.CancellationToken CancellationToken" />
<MemberSignature Language="DocId" Value="P:Azure.SyncAsyncEventArgs.CancellationToken" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property CancellationToken As CancellationToken" />
<MemberSignature Language="F#" Value="member this.CancellationToken : System.Threading.CancellationToken" Usage="Azure.SyncAsyncEventArgs.CancellationToken" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.Core</AssemblyName>
<AssemblyVersion>1.40.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Threading.CancellationToken</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets a cancellation token related to the original operation that
raised the event. It's important for your handler to pass this
token along to any asynchronous or long-running synchronous
operations that take a token so cancellation (via something like
<code>
new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token
</code>
for example) will correctly propagate.
</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="IsRunningSynchronously">
<MemberSignature Language="C#" Value="public bool IsRunningSynchronously { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsRunningSynchronously" />
<MemberSignature Language="DocId" Value="P:Azure.SyncAsyncEventArgs.IsRunningSynchronously" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property IsRunningSynchronously As Boolean" />
<MemberSignature Language="F#" Value="member this.IsRunningSynchronously : bool" Usage="Azure.SyncAsyncEventArgs.IsRunningSynchronously" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.Core</AssemblyName>
<AssemblyVersion>1.40.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets a value indicating whether the event handler was invoked
synchronously or asynchronously. Please see
<see cref="T:Azure.Core.SyncAsyncEventHandler`1" /> for more details.
</summary>
<value>To be added.</value>
<remarks>
<para>
The same <see cref="T:Azure.Core.SyncAsyncEventHandler`1" />
event can be raised from both synchronous and asynchronous code
paths depending on whether you're calling sync or async methods on
a client. If you write an async handler but raise it from a sync
method, the handler will be doing sync-over-async and may cause
ThreadPool starvation. See
<see href="https://docs.microsoft.com/archive/blogs/vancem/diagnosing-net-core-threadpool-starvation-with-perfview-why-my-service-is-not-saturating-all-cores-or-seems-to-stall">
Diagnosing .NET Core ThreadPool Starvation with PerfView</see> for
a detailed explanation of how that can cause ThreadPool starvation
and serious performance problems.
</para>
<para>
You can use this <see cref="P:Azure.SyncAsyncEventArgs.IsRunningSynchronously" /> property to check
how the event is being raised and implement your handler
accordingly. Here's an example handler that's safe to invoke from
both sync and async code paths.
<code snippet="Snippet:Azure_Core_Samples_EventSamples_CombinedHandler" language="csharp">
var client = new AlarmClient();
client.Ring += async (SyncAsyncEventArgs e) =>
{
if (e.IsRunningSynchronously)
{
Console.WriteLine("Wake up!");
}
else
{
await Console.Out.WriteLineAsync("Wake up!");
}
};
client.Snooze(); // sync call that blocks
await client.SnoozeAsync(); // async call that doesn't block
</code></para>
</remarks>
</Docs>
</Member>
</Members>
</Type>