コード例 #1
0
ファイル: ExpressionTest.cs プロジェクト: rafntor/bdhero
 public void TestThrowsWin32Exception()
 {
     Assert.Throws <Win32Exception>(delegate
     {
         var result1 = PInvokeUtils.Try(() => JobObjectAPI.CloseHandle(IntPtr.Zero), result => result);
     });
 }
コード例 #2
0
ファイル: ExpressionTest.cs プロジェクト: rafntor/bdhero
        public void TestReturnsResult()
        {
            var jobObjectHandle = IntPtr.Zero;

            try
            {
                jobObjectHandle = PInvokeUtils.Try(() => JobObjectAPI.CreateJobObject(IntPtr.Zero, null), result => result != IntPtr.Zero);

                Assert.AreNotEqual(jobObjectHandle, IntPtr.Zero);
            }
            finally
            {
                if (jobObjectHandle != IntPtr.Zero)
                {
                    JobObjectAPI.CloseHandle(jobObjectHandle);
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///     Frees managed and unmanaged resources.
        /// </summary>
        /// <param name="freeManagedObjectsAlso">
        ///     Free managed resources.  Should only be set to <c>true</c> when called from <see href="Dispose"/>.
        /// </param>
        /// <exception cref="Win32Exception">
        ///     Thrown if the handle to the Job Object could not be released.
        /// </exception>
        /// <seealso href="http://stackoverflow.com/a/538238/467582"/>
        private void Dispose(bool freeManagedObjectsAlso)
        {
            // Free unmanaged resources
            // ...

            // Free managed resources too, but only if I'm being called from Dispose()
            // (If I'm being called from Finalize then the objects might not exist anymore)
            if (freeManagedObjectsAlso)
            {
                if (_disposed)
                {
                    return;
                }
                if (_jobObjectHandle == IntPtr.Zero)
                {
                    return;
                }

                _disposed = true;

                PInvokeUtils.Try(() => JobObjectAPI.CloseHandle(_jobObjectHandle));
            }
        }