Exemplo n.º 1
0
        private async Task WriteLogsAsync()
        {
            while (!_disposed)
            {
                List <InvokeInfo> toWriteInvokes = null;
                lock (_logLock)
                {
                    if (_invokes.Count > 0)
                    {
                        toWriteInvokes = _invokes;
                        _invokes       = new List <InvokeInfo>();
                    }
                }

                if (toWriteInvokes != null)
                {
                    var pageSize  = 1000;
                    var pageCount = (toWriteInvokes.Count - 1) / pageSize + 1;
                    for (var idxPage = 0; idxPage < pageCount; idxPage++)
                    {
                        var currentPageItems = toWriteInvokes
                                               .Skip(idxPage * pageSize)
                                               .Take(pageSize)
                                               .ToArray();

                        for (var i = 0; i < 3; i++)
                        {
                            try
                            {
                                var   writeTask = _client.AddInvokesAsync(currentPageItems);
                                await writeTask;
                                break;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                    }
                }

                await Task.Delay(10 * 1000);
            }
        }