C# Class 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.)

Afficher le fichier Open project: Invenietis/ck-core Class Usage Examples

Méthodes publiques

Méthode Description
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.

Private Methods

Méthode Description
CreateEvent ( ) : ErrorEventArgs

Method Details

Add() public méthode

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.
Résultat void

Clear() public méthode

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
Résultat void

Clear() public méthode

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.
Résultat void

CriticalErrorCollector() public méthode

Initializes a new CriticalErrorCollector with a default Capacity set to 128.
public CriticalErrorCollector ( ) : System
Résultat System

DoRaiseInBackground() public méthode

public DoRaiseInBackground ( object unusedState ) : void
unusedState object
Résultat void

ToArray() public méthode

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[]
Résultat Error[]

WaitOnErrorFromBackgroundThreadsPending() public méthode

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
Résultat void