MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / Start

Method Start

PerformanceMonitor/DebugMonitor.cs:167–230  ·  view source on GitHub ↗

Starts this debug monitor

()

Source from the content-addressed store, hash-verified

165 /// Starts this debug monitor
166 /// </summary>
167 public static void Start() {
168 lock (m_SyncRoot) {
169 if (m_Capturer != null)
170 throw new ApplicationException("This DebugMonitor is already started.");
171
172 // Check for supported operating system. Mono (at least with *nix) won't support
173 // our P/Invoke calls.
174 if (Environment.OSVersion.ToString().IndexOf("Microsoft") == -1)
175 throw new NotSupportedException("This DebugMonitor is only supported on Microsoft operating systems.");
176
177 // Check for multiple instances. As the README.TXT of the msdn
178 // example notes it is possible to have multiple debug monitors
179 // listen on OutputDebugString, but the message will be randomly
180 // distributed among all running instances so this won't be
181 // such a good idea.
182 bool createdNew = false;
183 m_Mutex = new Mutex(false, typeof(DebugMonitor).Namespace, out createdNew);
184 if (!createdNew)
185 throw new ApplicationException("There is already an instance of 'DbMon.NET' running.");
186
187 SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR();
188
189 // Initialize the security descriptor.
190 if (!InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION)) {
191 throw CreateApplicationException("Failed to initializes the security descriptor.");
192 }
193
194 // Set information in a discretionary access control list
195 if (!SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false)) {
196 throw CreateApplicationException("Failed to initializes the security descriptor");
197 }
198
199 SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
200
201 // Create the event for slot 'DBWIN_BUFFER_READY'
202 m_AckEvent = CreateEvent(ref sa, false, false, "DBWIN_BUFFER_READY");
203 if (m_AckEvent == IntPtr.Zero) {
204 throw CreateApplicationException("Failed to create event 'DBWIN_BUFFER_READY'");
205 }
206
207 // Create the event for slot 'DBWIN_DATA_READY'
208 m_ReadyEvent = CreateEvent(ref sa, false, false, "DBWIN_DATA_READY");
209 if (m_ReadyEvent == IntPtr.Zero) {
210 throw CreateApplicationException("Failed to create event 'DBWIN_DATA_READY'");
211 }
212
213 // Get a handle to the readable shared memory at slot 'DBWIN_BUFFER'.
214 m_SharedFile = CreateFileMapping(new IntPtr(-1), ref sa, PageProtection.ReadWrite, 0, 4096, "DBWIN_BUFFER");
215 if (m_SharedFile == IntPtr.Zero) {
216 throw CreateApplicationException("Failed to create a file mapping to slot 'DBWIN_BUFFER'");
217 }
218
219 // Create a view for this file mapping so we can access it
220 m_SharedMem = MapViewOfFile(m_SharedFile, SECTION_MAP_READ, 0, 0, 512);
221 if (m_SharedMem == IntPtr.Zero) {
222 throw CreateApplicationException("Failed to create a mapping view for slot 'DBWIN_BUFFER'");
223 }
224

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected