public static async Task <EsentSession> CreateReadOnlySession(IEsentSession parentSession, IDisposeWaiters waiters)
            {
                var dispatcher = new SingleThreadDispatcher();

                try
                {
                    return(await dispatcher.QueueAction(() =>
                    {
                        var session = new Session(parentSession.Instance);
                        try
                        {
                            Api.JetAttachDatabase(session, parentSession.DatabaseFile, AttachDatabaseGrbit.None);
                            JET_DBID dbid;
                            Api.JetOpenDatabase(session, parentSession.DatabaseFile, string.Empty, out dbid, OpenDatabaseGrbit.None);
                            // ReSharper disable once AccessToDisposedClosure
                            return new EsentSession(parentSession.Instance, session, dbid, parentSession.DatabaseFile, waiters, dispatcher, true);
                        }
                        catch
                        {
                            session.Dispose();
                            throw;
                        }
                    }));
                }
                catch
                {
                    dispatcher.Dispose();
                    throw;
                }
            }
        private async Task CreateCachedInstance()
        {
            var dispatcher = new SingleThreadDispatcher();

            try
            {
                // ReSharper disable once AccessToDisposedClosure
                var mainSession = await dispatcher.QueueAction(() => CreateInstance(dispatcher));

                var newSession = new MainSessionObj()
                {
                    MainSession = mainSession,
                    Waiters     = this
                };
                await newSession.CreateReservedSessions();

                var old = Interlocked.Exchange(ref _cachedSession, newSession);
                if (old != null)
                {
                    await old.DisposeAsync();
                }
            }
            catch
            {
                dispatcher.Dispose();
                throw;
            }
        }