What is the safest way to subtract two System.Runtime.InteropServices.ComTypes.FILETIME objects
- by Anindya Chatterjee
I wonder what is the safest way to subtract two System.Runtime.InteropServices.ComTypes.FILETIME objects? I used the following code but sometimes it gives me ArithmaticOverflow exception due to the negative number in Low 32-bit values. I am not sure enclosing the body with unchecked will serve the purpose or not. Please give me some suggestion on how to do it safely without getting any runtime exception or CS0675 warning message.
private static UInt64 SubtractTimes(FILETIME a, FILETIME b)
{
UInt64 aInt = ((UInt64)(a.dwHighDateTime << 32)) | (UInt32)a.dwLowDateTime;
UInt64 bInt = ((UInt64)(b.dwHighDateTime << 32)) | (UInt32)b.dwLowDateTime;
return aInt - bInt;
}