private int FlushLoop()
        {
            _UploadingNow = true;
            int processedCount = 0;

            try
            {
                int queueSize = _MessageBuffer.Count;

                // StackifyLib.Utils.StackifyAPILogger.Log("FlushLoop - count: " + queueSize + " for " + _LogClient.LoggerName);

                //CanSend() does an IdentifyApp so there is a chance this could take a while
                if (queueSize > 0 && _LogClient.CanUpload())
                {
                    _QueueTooBig = queueSize < Logger.MaxLogBufferSize;

                    bool keepGoing = false;

                    int flushTimes = 0;
                    //Keep flushing
                    do
                    {
                        int count = FlushOnce();

                        if (count >= 100)
                        {
                            keepGoing = true;
                        }
                        else
                        {
                            keepGoing = false;
                        }
                        flushTimes++;
                        processedCount += count;
                    } while (keepGoing && flushTimes < 25);

                    _QueueTooBig = _MessageBuffer.Count < Logger.MaxLogBufferSize;
                }
            }
            catch (Exception ex)
            {
                StackifyAPILogger.Log("#LogQueue #FlushLoop failed", ex);
            }
            _UploadingNow = false;
            return(processedCount);
        }
Example #2
0
        private int FlushLoop()
        {
            _UploadingNow = true;
            int processedCount = 0;

            try
            {
                int queueSize = _MessageBuffer.Count;

                // StackifyLib.Utils.StackifyAPILogger.Log("FlushLoop - count: " + queueSize + " for " + _LogClient.LoggerName);

                //CanSend() does an IdentifyApp so there is a chance this could take a while
                if (queueSize > 0 && _LogClient.CanUpload())
                {
                    _QueueTooBig = queueSize < Logger.MaxLogBufferSize;

                    bool keepGoing = false;

                    var tasks = new List <Task>();

                    int flushTimes = 0;
                    //Keep flushing
                    do
                    {
                        int count;
                        var task = FlushOnceAsync(out count);

                        if (task != null)
                        {
                            tasks.Add(task);
                        }

                        if (count >= 100)
                        {
                            keepGoing = true;
                        }
                        else
                        {
                            keepGoing = false;
                        }
                        flushTimes++;
                        processedCount += count;
                    } while (keepGoing && flushTimes < 25);


                    if (_StopRequested && tasks.Any())
                    {
                        StackifyLib.Utils.StackifyAPILogger.Log("Waiting to ensure final log send. Waiting on " + tasks.Count + " tasks");
                        Task.WaitAll(tasks.ToArray(), 5000);
                        StackifyLib.Utils.StackifyAPILogger.Log("Final log flush complete");
                    }

                    _QueueTooBig = _MessageBuffer.Count < Logger.MaxLogBufferSize;
                }
            }
            catch (Exception ex)
            {
                StackifyLib.Utils.StackifyAPILogger.Log(ex.ToString());
            }
            _UploadingNow = false;
            return(processedCount);
        }