Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Invoke() [1/2]

static void System.Threading.Tasks.Parallel.Invoke ( ParallelOptions parallelOptions,
params Action[] actions )
inlinestatic

Definition at line 157 of file Parallel.cs.

158 {
159 ParallelOptions parallelOptions2 = parallelOptions;
160 if (actions == null)
161 {
162 throw new ArgumentNullException("actions");
163 }
164 if (parallelOptions2 == null)
165 {
166 throw new ArgumentNullException("parallelOptions");
167 }
168 parallelOptions2.CancellationToken.ThrowIfCancellationRequested();
169 Action[] actionsCopy = new Action[actions.Length];
170 for (int i = 0; i < actionsCopy.Length; i++)
171 {
173 if (actionsCopy[i] == null)
174 {
176 }
177 }
178 int forkJoinContextID = 0;
179 if (ParallelEtwProvider.Log.IsEnabled())
180 {
181 forkJoinContextID = Interlocked.Increment(ref s_forkJoinContextID);
182 ParallelEtwProvider.Log.ParallelInvokeBegin(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID, ParallelEtwProvider.ForkJoinOperationType.ParallelInvoke, actionsCopy.Length);
183 }
184 if (actionsCopy.Length < 1)
185 {
186 return;
187 }
188 try
189 {
190 if (OperatingSystem.IsBrowser() || actionsCopy.Length > 10 || (parallelOptions2.MaxDegreeOfParallelism != -1 && parallelOptions2.MaxDegreeOfParallelism < actionsCopy.Length))
191 {
193 int actionIndex = 0;
194 try
195 {
196 TaskReplicator.Run(delegate(ref object state, int timeout, out bool replicationDelegateYieldedBeforeCompletion)
197 {
199 for (int num = Interlocked.Increment(ref actionIndex); num <= actionsCopy.Length; num = Interlocked.Increment(ref actionIndex))
200 {
201 try
202 {
203 actionsCopy[num - 1]();
204 }
205 catch (Exception item)
206 {
207 LazyInitializer.EnsureInitialized(ref exceptionQ, () => new ConcurrentQueue<Exception>());
208 exceptionQ.Enqueue(item);
209 }
210 parallelOptions2.CancellationToken.ThrowIfCancellationRequested();
211 }
213 }
214 catch (Exception ex)
215 {
216 LazyInitializer.EnsureInitialized(ref exceptionQ, () => new ConcurrentQueue<Exception>());
217 if (ex is ObjectDisposedException)
218 {
219 throw;
220 }
221 if (ex is AggregateException ex2)
222 {
223 foreach (Exception innerException in ex2.InnerExceptions)
224 {
225 exceptionQ.Enqueue(innerException);
226 }
227 }
228 else
229 {
230 exceptionQ.Enqueue(ex);
231 }
232 }
233 if (exceptionQ != null && !exceptionQ.IsEmpty)
234 {
236 }
237 return;
238 }
239 Task[] array = new Task[actionsCopy.Length];
240 parallelOptions2.CancellationToken.ThrowIfCancellationRequested();
241 for (int j = 1; j < array.Length; j++)
242 {
243 array[j] = Task.Factory.StartNew(actionsCopy[j], parallelOptions2.CancellationToken, TaskCreationOptions.None, parallelOptions2.EffectiveTaskScheduler);
244 }
245 array[0] = new Task(actionsCopy[0], parallelOptions2.CancellationToken, TaskCreationOptions.None);
246 array[0].RunSynchronously(parallelOptions2.EffectiveTaskScheduler);
247 try
248 {
249 Task.WaitAll(array);
250 }
251 catch (AggregateException ex3)
252 {
254 }
255 }
256 finally
257 {
258 if (ParallelEtwProvider.Log.IsEnabled())
259 {
260 ParallelEtwProvider.Log.ParallelInvokeEnd(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID);
261 }
262 }
263 }
static string Parallel_Invoke_ActionNull
Definition SR.cs:14
Definition SR.cs:7
static void ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
Definition Parallel.cs:1447

References System.array, System.Threading.Tasks.TaskScheduler.Current, System.Threading.Tasks.Task< TResult >.CurrentId, System.Threading.Tasks.Task< TResult >.Factory, System.Threading.Interlocked.Increment(), System.OperatingSystem.IsBrowser(), System.item, System.Threading.Tasks.ParallelEtwProvider.Log, System.SR.Parallel_Invoke_ActionNull, System.Threading.Tasks.Parallel.s_forkJoinContextID, System.state, System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(), System.timeout, and System.Threading.Tasks.Task< TResult >.WaitAll().