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.)

Show file Open project: Invenietis/ck-core Class Usage Examples

Public Methods

Method 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

Method Description
CreateEvent ( ) : ErrorEventArgs

Method Details

Add() public method

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.
return void

Clear() public method

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
return void

Clear() public method

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.
return void

CriticalErrorCollector() public method

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

DoRaiseInBackground() public method

public DoRaiseInBackground ( object unusedState ) : void
unusedState object
return void

ToArray() public method

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[]
return Error[]

WaitOnErrorFromBackgroundThreadsPending() public method

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
return void