Ejemplo n.º 1
0
        private void CacheWriteTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            try
            {
                Collection <MachineStatusInflux> tempToWriteItems = measurementsThatNeedToBeWrittenToDB.Clone();

                //** Stores current measurementsThatNeedToBeWrittenToDB in a temp variable so that we know which ones we are trying to write, (More maybe added while we are processing)

                repository.WriteAsync(tempToWriteItems).GetAwaiter();

                //** if WriteAsync did not throw an exception we can assume the items were written to the database and we can remove them from measurementsThatNeedToBeWrittenToDB

                measurementsThatNeedToBeWrittenToDB.RemoveMany(tempToWriteItems);
            }
            catch (Exception ex)
            {
                _logger()?.Error(ex, "Issue While Handling cache write");
            }
            finally
            {
                sw.Stop();
                _logger()?.Debug("This Method took {elapsed}", sw.Elapsed);
            }
        }