Ejemplo n.º 1
0
        public Instance(string name, string displayName, TermGrbit termGrbit) : base(true)
        {
            this.name        = name;
            this.displayName = displayName;
            this.termGrbit   = termGrbit;

            JET_INSTANCE instance;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                this.SetHandle(JET_INSTANCE.Nil.Value);
            }
            finally
            {
                // This is the code that we want in a constrained execution region.
                // We need to avoid the situation where JetCreateInstance2 is called
                // but the handle isn't set, so the instance is never terminated.
                // This would happen, for example, if there was a ThreadAbortException
                // between the call to JetCreateInstance2 and the call to SetHandle.
                //
                // If an Esent exception is generated we do not want to call SetHandle
                // because the instance isn't valid. On the other hand if a different
                // exception (out of memory or thread abort) is generated we still need
                // to set the handle to avoid losing track of the instance. The call to
                // JetCreateInstance2 is in the CER to make sure that the only exceptions
                // which can be generated are from ESENT failures.
                Api.JetCreateInstance2(out instance, this.name, this.displayName, CreateInstanceGrbit.None);
                this.SetHandle(instance.Value);
            }

            this.parameters = new InstanceParameters(instance);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Terminate an instance that was created with <see cref="JetInit"/> or
 /// <see cref="JetCreateInstance"/>.
 /// </summary>
 /// <param name="instance">The instance to terminate.</param>
 /// <param name="grbit">Termination options.</param>
 public static void JetTerm2(JET_INSTANCE instance, TermGrbit grbit)
 {
     Api.Check(Impl.JetTerm2(instance, grbit));
 }