コード例 #1
0
        public async Task SaveChangesAsync()
        {
            _saving = true;
            List <ChatMessageDto> temp;

            lock (_syncRoot)
            {
                temp             = _pendingMessages;
                _pendingMessages = new List <ChatMessageDto>();
            }
            var context = new MessagesContext();

            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled    = false;
            // ReSharper disable once AccessToDisposedClosure
            await Task.Run(() => { context.BulkInsert(temp); });

            context.Dispose();
            SaveCompleted.Invoke(this, DateTime.Now);
            _saving = false;
        }