Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UserAsyncDispatcher.cs
Go to the documentation of this file.
1using System;
5
7
8internal static class UserAsyncDispatcher
9{
11
12 internal static readonly object PendingOperationsLock = new object();
13
15
16 private static bool initialized = false;
17
18 private unsafe static void PlatformSpecificInitialize()
19 {
22 if (parentExitEvent.IsInvalid)
23 {
25 }
26 AppDomain.CurrentDomain.ProcessExit += OnExit;
27 AppDomain.CurrentDomain.DomainUnload += OnExit;
30 }
31
32 private static void OnExit(object sender, EventArgs e)
33 {
34 if (!parentExitEvent.IsInvalid)
35 {
36 UnsafeNativeMethods.SetEvent(parentExitEvent.DangerousGetHandle());
37 }
38 }
39
44
45 internal static void Initialize()
46 {
47 if (!initialized)
48 {
51 thread.IsBackground = true;
52 thread.Start();
53 initialized = true;
54 }
55 }
56
79
87
89 {
90 if (managedCallType != ManagedCallType.Media_ActiveSongChanged && managedCallType != ManagedCallType.Media_PlayStateChanged && managedCallType != ManagedCallType.CaptureBufferReady)
91 {
92 return managedCallType == ManagedCallType.PlaybackBufferNeeded;
93 }
94 return true;
95 }
96
97 private static void HandleFinishedOperation(uint finishedHandle)
98 {
101 {
103 if (!pendingOp.Async.IsReusable)
104 {
106 pendingOp.Async.IsCompleted = true;
107 }
108 }
109 pendingOp.Async.AsyncWaitHandle.Set();
110 if (pendingOp.Callback != null)
111 {
113 {
114 pendingOp.Callback(pendingOp.Async);
115 });
116 }
117 }
118
119 internal static IAsyncResult AddPendingOperation(uint kernelHandle, AsyncCallback callback, object asyncState)
120 {
121 return AddPendingOperation(kernelHandle, callback, asyncState, isReusable: false, null);
122 }
123
124 internal static IAsyncResult AddPendingOperation(uint kernelHandle, AsyncCallback callback, object asyncState, bool isReusable, AsyncOperationCleanup operationCleanup)
125 {
127 pendingOperations.Add(kernelHandle, new PendingOperation(xOverlappedAsyncResult, callback));
129 }
130
132 {
134 {
135 return pendingOperations.ContainsKey(result.KernelHandle);
136 }
137 }
138}
static void AddNewPendingCall(ManagedCallType callType, uint arg)
static void ThrowExceptionFromResult(uint result)
Definition Helpers.cs:103
static IntPtr CreateEvent(ref SecurityAttributes lpEventAttributes, [MarshalAs(UnmanagedType.Bool)] bool bManualReset, [MarshalAs(UnmanagedType.Bool)] bool bInitialState, IntPtr lpName)
static Dictionary< uint, PendingOperation > pendingOperations
static IAsyncResult AddPendingOperation(uint kernelHandle, AsyncCallback callback, object asyncState, bool isReusable, AsyncOperationCleanup operationCleanup)
static KernelReturnCode WaitForAsyncOperationToFinish(out ManagedCallType managedCallType, out uint managedCallArgs)
static void HandleFinishedOperation(uint finishedHandle)
static bool CallbackGoesToDispatcher(ManagedCallType managedCallType)
static bool OperationStillPending(XOverlappedAsyncResult result)
static void OnExit(object sender, EventArgs e)
static IAsyncResult AddPendingOperation(uint kernelHandle, AsyncCallback callback, object asyncState)
static void HandleManagedCallback(ManagedCallType managedCallType, uint managedCallArgs)
static bool QueueUserWorkItem(WaitCallback callBack)
static readonly IntPtr Zero
Definition IntPtr.cs:18