예제 #1
0
 public ResourceUser()
 {
     handle = APIFunctionSimulator.GetResource();
     if (handle.ToInt32() == 0)
     {
         throw new ApplicationException();
     }
 }
예제 #2
0
        public void UseResource()
        {
            if (handle.ToInt32() == 0)
            {
                throw new ObjectDisposedException("handle used in UseResource class after object disposed");
            }
            string result = APIFunctionSimulator.UseResource(handle);

            Console.WriteLine("In ResourceUser.UseResource, result is :" + result);
        }
예제 #3
0
 public void Dispose()
 {
     lock (this)
     {
         if (handle.ToInt32() != 0)
         {
             APIFunctionSimulator.ReleaseResource(handle);
             handle = (IntPtr)0;
             GC.SuppressFinalize(this);
         }
     }
 }
예제 #4
0
        static void UseUnmanagedResource()
        {
            IntPtr handle = APIFunctionSimulator.GetResource();

            try
            {
                string result = APIFunctionSimulator.UseResource(handle);
                Console.WriteLine("In EntryPoint.UseUnmanagedResource, result is :" + result);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in UseUnmanagedResource: " + e.Message);
            }
            finally
            {
                if (handle.ToInt32() != 0)
                {
                    APIFunctionSimulator.ReleaseResource(handle);
                }
            }
        }