예제 #1
0
        public void VerifyJetSetSessionContextAllowsThreadMigration()
        {
            using (var instance = new Instance("JetSetSessionContext"))
            {
                SetupHelper.SetLightweightConfiguration(instance);
                instance.Init();
                using (var session = new Session(instance))
                {
                    // Without the calls to JetSetSessionContext/JetResetSessionContext
                    // this will generate a session sharing violation.
                    var context = new IntPtr(Any.Int32);

                    var thread = new Thread(() =>
                    {
                        EseInteropTestHelper.ThreadBeginThreadAffinity();
                        Api.JetSetSessionContext(session, context);
                        Api.JetBeginTransaction(session);
                        Api.JetResetSessionContext(session);
                        EseInteropTestHelper.ThreadEndThreadAffinity();
                    });
                    thread.Start();
                    thread.Join();

                    Api.JetSetSessionContext(session, context);
                    Api.JetCommitTransaction(session, CommitTransactionGrbit.None);
                    Api.JetResetSessionContext(session);
                }
            }
        }
예제 #2
0
            /// <summary>
            /// Process the records sequentially. This method tries
            /// to lock a record and moves to the next record if
            /// it fails to get the lock.
            /// </summary>
            public void DoWork()
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();

                // We must be in a transaction for locking to work.
                using (var transaction = new Transaction(this.sesid))
                {
                    if (Api.TryMoveFirst(this.sesid, this.tableid))
                    {
                        do
                        {
                            // Getting a lock in ESENT is instantaneous -- if
                            // another thread has the record locked or has
                            // updated this record, this call will fail. There
                            // is no way to wait for the lock to be released.
                            // (because ESENT uses Snapshot Isolation the other
                            // session's lock will always be visible until this
                            // transaction commits).
                            if (Api.TryGetLock(this.sesid, this.tableid, GetLockGrbit.Write))
                            {
                                // [Do something]
                                EseInteropTestHelper.ThreadSleep(1);
                                Api.JetDelete(this.sesid, this.tableid);
                                this.RecordsProcessed++;
                            }
                        }while (Api.TryMoveNext(this.sesid, this.tableid));
                    }

                    transaction.Commit(CommitTransactionGrbit.LazyFlush);
                }

                EseInteropTestHelper.ThreadEndThreadAffinity();
            }
예제 #3
0
            /// <summary>
            /// Called for the disposer and finalizer.
            /// </summary>
            /// <param name="isDisposing">True if called from dispose.</param>
            protected virtual void Dispose(bool isDisposing)
            {
                if (isDisposing)
                {
                    this.session.Dispose();
                }

                EseInteropTestHelper.ThreadEndThreadAffinity();
            }
예제 #4
0
        public void VerifyJetSetSessionContextAllowsThreadMigration()
        {
            // Without the calls to JetSetSessionContext/JetResetSessionContext
            // this will generate a session sharing violation.
            var context = new IntPtr(Any.Int32);

            var thread = new Thread(() =>
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();
                Api.JetSetSessionContext(this.sesid, context);
                Api.JetBeginTransaction(this.sesid);
                Api.JetResetSessionContext(this.sesid);
                EseInteropTestHelper.ThreadEndThreadAffinity();
            });

            thread.Start();
            thread.Join();

            Api.JetSetSessionContext(this.sesid, context);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None);
            Api.JetResetSessionContext(this.sesid);
        }
예제 #5
0
 /// <summary>
 /// Called for the disposer and finalizer.
 /// </summary>
 /// <param name="isDisposing">True if called from dispose.</param>
 protected virtual void Dispose(bool isDisposing)
 {
     EseInteropTestHelper.ThreadEndThreadAffinity();
 }