Exemple #1
0
        private SqliteProfilerDataService EnsureDataServiceAndDeleteOldFiles(SqliteProfilerDataService dataService)
        {
            string filePath = null;

            if (dataService == null || (DateTime.Today != this.lastDataServiceCreateDay && dataService.FilePath != (filePath = this.GetDatabaseFilePath())))
            {
                TryDisposeDataService(dataService);
                if (filePath == null)
                {
                    filePath = this.GetDatabaseFilePath();
                }
                dataService = SqliteProfilerDataService.Create(filePath);
                lastDataServiceCreateDay = DateTime.Today;
                dataService.OpenConnection();
                ThreadPool.QueueUserWorkItem(DeleteOldFiles);
            }
            return(dataService);
        }
Exemple #2
0
        private SqliteProfilerDataService EnsureDataServiceAndDeleteOldFiles(SqliteProfilerDataService dataService)
        {
            string filePath = null;

            if (dataService == null || (DateTime.Today != this.lastDataServiceCreateDay && dataService.FilePath != (filePath = this.GetDatabaseFilePath())))
            {
                TryDisposeDataService(dataService);
                if (filePath == null)
                {
                    filePath = this.GetDatabaseFilePath();
                }
                int attempt = 1;
                while (true)
                {
                    try
                    {
                        dataService = SqliteProfilerDataService.Create(filePath);
                        lastDataServiceCreateDay = DateTime.Today;
                        dataService.OpenConnection();
                        ThreadPool.QueueUserWorkItem(DeleteOldFiles);
                        return(dataService);
                    }
                    catch
                    {
                        TryDisposeDataService(dataService);
                        if (++attempt > 20)
                        {
                            throw;
                        }
                        Thread.Sleep(200);
                    }
                    finally
                    {
                        if (attempt > MaxDataServiceAttempts)
                        {
                            MaxDataServiceAttempts = attempt;
                        }
                    }
                }
            }
            return(dataService);
        }