Esempio n. 1
0
        public void Start()
        {
            var state = new object();

            _tokenSource = new CancellationTokenSource();

            Task.Run(async() =>
            {
                do
                {
                    try
                    {
                        var blockingQueue = await _applicationInsights.GetQueue();

                        var data = blockingQueue.Dequeue();

                        foreach (var provider in _insightProviders.Values)
                        {
                            if (provider != null)
                            {
                                await provider.Record(data);
                            }
                        }
                    }
                    catch
                    {
                        await Task.Delay(5000); // Pause to avoid thrashing if continual failure
                    }
                } while (true);
            }, _tokenSource.Token);
        }
Esempio n. 2
0
        /// <summary>
        /// Will get the data from application insights and send them to the appropriate place
        /// </summary>
        /// <param name="state"></param>
        private async Task ProcessData(object state)
        {
            lock (_runningLock)
            {
                if (isRunning)
                {
                    return;
                }
                isRunning = true;
            }

            var list = await _applicationInsights.GetQueue();

            foreach (var item in list)
            {
                foreach (var provider in _insightProviders.Values)
                {
                    if (provider != null)
                    {
                        await provider.Send(item);
                    }
                }
            }

            await _applicationInsights.Clear(list);

            isRunning = false;
        }