@@ -55,7 +55,7 @@ static ObjectId()
55
55
56
56
try
57
57
{
58
- SetPidToCurrentProcessId ( ) ;
58
+ __staticPid = GetCurrentProcessId ( ) ;
59
59
}
60
60
catch ( SecurityException )
61
61
{
@@ -362,6 +362,17 @@ public static void Unpack(byte[] bytes, out int timestamp, out int machine, out
362
362
}
363
363
364
364
// private static methods
365
+ /// <summary>
366
+ /// Gets the current process id. This method exists because of how CAS operates on the call stack, checking
367
+ /// for permissions before executing the method. Hence, if we inlined this call, the calling method would not execute
368
+ /// before throwing an exception requiring the try/catch at an even higher level that we don't necessarily control.
369
+ /// </summary>
370
+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
371
+ private static short GetCurrentProcessId ( )
372
+ {
373
+ return ( short ) Process . GetCurrentProcess ( ) . Id ;
374
+ }
375
+
365
376
private static int GetMachineHash ( )
366
377
{
367
378
var hostName = Environment . MachineName ; // use instead of Dns.HostName so it will work offline
@@ -375,17 +386,6 @@ private static int GetTimestampFromDateTime(DateTime timestamp)
375
386
return ( int ) Math . Floor ( ( BsonUtils . ToUniversalTime ( timestamp ) - BsonConstants . UnixEpoch ) . TotalSeconds ) ;
376
387
}
377
388
378
- /// <summary>
379
- /// Sets the pid to current process id. This method exists because of how CAS operates on the call stack, checking
380
- /// for permissions before executing the method. Hence, if we inlined this call, the calling method would not execute
381
- /// before throwing an exception requiring the try/catch at an even higher level that we don't necessarily control.
382
- /// </summary>
383
- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
384
- private static void SetPidToCurrentProcessId ( )
385
- {
386
- __staticPid = ( short ) Process . GetCurrentProcess ( ) . Id ;
387
- }
388
-
389
389
// public methods
390
390
/// <summary>
391
391
/// Compares this ObjectId to another ObjectId.
0 commit comments