Beispiel #1
0
        private void StartAsyncLogFileWriterThread(string formattedMessage)
        {
            lock (_pendingLogWorkersStackLock)
            {
                PendingLogWorker pendingLogBackgroundWorker = null;

                try
                {
                    pendingLogBackgroundWorker = new PendingLogWorker(formattedMessage);
                    pendingLogBackgroundWorker.BackgroundWorker.DoWork             += AsyncLog;
                    pendingLogBackgroundWorker.BackgroundWorker.RunWorkerCompleted += AsyncLogCompleted;
                    _pendingLogWorkersStack.Add(pendingLogBackgroundWorker);

                    if (_pendingLogWorkersStack.Count == 1) //
                    {
                        _autoResetEvent.Reset();
                        pendingLogBackgroundWorker.Run();
                    }
                }
                catch (Exception ex)
                {
                    if (pendingLogBackgroundWorker != null)
                    {
                        _pendingLogWorkersStack.Remove(pendingLogBackgroundWorker);
                    }
                }
            }
        }
        private void StartAsyncLogFileWriterThread(string formattedMessage)
        {
            lock (_pendingLogWorkersStackLock)
            {
                PendingLogWorker pendingLogBackgroundWorker = null;

                try
                {
                    pendingLogBackgroundWorker = new PendingLogWorker(formattedMessage);
                    pendingLogBackgroundWorker.BackgroundWorker.DoWork += AsyncLog;
                    pendingLogBackgroundWorker.BackgroundWorker.RunWorkerCompleted += AsyncLogCompleted;
                    _pendingLogWorkersStack.Add(pendingLogBackgroundWorker);

                    if (_pendingLogWorkersStack.Count == 1) //
                    {
                        _autoResetEvent.Reset();
                        pendingLogBackgroundWorker.Run();
                    }
                }
                catch (Exception ex)
                {
                    if (pendingLogBackgroundWorker != null)
                    {
                        _pendingLogWorkersStack.Remove(pendingLogBackgroundWorker);
                    }
                }
            }
        }