public ResourceUser()
 {
     handle = APIFunctionSimulator.GetResource();
     if (handle.ToInt32() == 0)
     {
         throw new ApplicationException();
     }
 }
        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);
        }
 private void Dispose(bool disposing)
 {
     if (handle.ToInt32() != 0)
     {
         APIFunctionSimulator.ReleaseResource(handle);
         handle = (IntPtr)0;
     }
     if (disposing)
     {
         bigArray = null;
     }
 }
        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);
                }
            }
        }