C# Класс CK.Core.CriticalErrorCollector

This collector keeps Capacity Errors (and no more). It raises OnErrorFromBackgroundThreads event on each Add. It is totally thread-safe and guaranties (as long as its Capacity is big enough) that no error can be lost (even errors raised while dispatching the event are themselves collected) and that errors are dispatched in sequence.

This class is typically used as a static property or field by any object that must handle unexpected errors. (It can also be used per-instance if it makes sense.)

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Add ( Exception ex, string comment ) : void

Adds a critical, unexpected error.

Clear ( ) : void

Clears the list. Only errors that have been already raised by OnErrorFromBackgroundThreads are removed from the internal buffer: it can be safely called at any time.

Clear ( int &cleared, int &waitingToBeRaisedErrors ) : void

Clears the list. Only errors that have been already raised by OnErrorFromBackgroundThreads are removed from the internal buffer: it can be safely called at any time.

CriticalErrorCollector ( ) : System

Initializes a new CriticalErrorCollector with a default Capacity set to 128.

DoRaiseInBackground ( object unusedState ) : void
ToArray ( ) : Error[]

Obtains a copy of the last (up to) Capacity errors from oldest to newest. The newest may have not been raised by OnErrorFromBackgroundThreads yet.

WaitOnErrorFromBackgroundThreadsPending ( ) : void

Blocks the caller thread until no more event is waiting to be raised by OnErrorFromBackgroundThreads or is being processed. This is the right function to use instead of pooling OnErrorFromBackgroundThreadsPending.

Приватные методы

Метод Описание
CreateEvent ( ) : ErrorEventArgs

Описание методов

Add() публичный Метод

Adds a critical, unexpected error.
public Add ( Exception ex, string comment ) : void
ex System.Exception The unexpected exception. Must not be null.
comment string Comment associated to the error (such as the name of the culprit). Can be null.
Результат void

Clear() публичный Метод

Clears the list. Only errors that have been already raised by OnErrorFromBackgroundThreads are removed from the internal buffer: it can be safely called at any time.
public Clear ( ) : void
Результат void

Clear() публичный Метод

Clears the list. Only errors that have been already raised by OnErrorFromBackgroundThreads are removed from the internal buffer: it can be safely called at any time.
public Clear ( int &cleared, int &waitingToBeRaisedErrors ) : void
cleared int Number of suppressed errors.
waitingToBeRaisedErrors int The number of errors waiting to be raised.
Результат void

CriticalErrorCollector() публичный Метод

Initializes a new CriticalErrorCollector with a default Capacity set to 128.
public CriticalErrorCollector ( ) : System
Результат System

DoRaiseInBackground() публичный Метод

public DoRaiseInBackground ( object unusedState ) : void
unusedState object
Результат void

ToArray() публичный Метод

Obtains a copy of the last (up to) Capacity errors from oldest to newest. The newest may have not been raised by OnErrorFromBackgroundThreads yet.
public ToArray ( ) : Error[]
Результат Error[]

WaitOnErrorFromBackgroundThreadsPending() публичный Метод

Blocks the caller thread until no more event is waiting to be raised by OnErrorFromBackgroundThreads or is being processed. This is the right function to use instead of pooling OnErrorFromBackgroundThreadsPending.
public WaitOnErrorFromBackgroundThreadsPending ( ) : void
Результат void