LaunchDarkly Dotnet Client SDK
Search Results for

    Show / Hide Table of Contents

    Class EventSource

    Provides an EventSource client for consuming Server-Sent Events. Additional details on the Server-Sent Events spec can be found at https://html.spec.whatwg.org/multipage/server-sent-events.html

    Inheritance
    object
    EventSource
    Implements
    IEventSource
    IDisposable
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: LaunchDarkly.EventSource
    Assembly: LaunchDarkly.EventSource.dll
    Syntax
    public class EventSource : IEventSource, IDisposable

    Constructors

    EventSource(Configuration)

    Initializes a new instance of the EventSource class.

    Declaration
    public EventSource(Configuration configuration)
    Parameters
    Type Name Description
    Configuration configuration

    the configuration

    EventSource(Uri)

    Shortcut for initializing an EventSource with only a stream URI and no custom properties.

    Declaration
    public EventSource(Uri uri)
    Parameters
    Type Name Description
    Uri uri

    the stream URI

    Exceptions
    Type Condition
    ArgumentNullException

    if the URI is null

    Properties

    ReadyState

    Gets the state of the EventSource connection.

    Declaration
    public ReadyState ReadyState { get; }
    Property Value
    Type Description
    ReadyState

    Methods

    Close()

    Closes the connection to the SSE server. The EventSource cannot be reopened after this.

    Declaration
    public void Close()

    Dispose()

    Equivalent to calling Close().

    Declaration
    public void Dispose()

    Restart(bool)

    Triggers the same "close and retry" behavior as if an error had been encountered on the stream.

    Declaration
    public void Restart(bool resetBackoffDelay)
    Parameters
    Type Name Description
    bool resetBackoffDelay

    true if the delay before reconnection should be reset to the lowest level (InitialRetryDelay(TimeSpan)); false if it should increase according to the usual exponential backoff logic

    Remarks

    If the stream is currently active, this closes the connection, waits for some amount of time as determined by the usual backoff behavior (and resetBackoffDelay), and then attempts to reconnect. If the stream is not yet connected, is already waiting to reconnect, or has been permanently shut down, this has no effect.

    The method returns immediately without waiting for the reconnection to happen. You will receive Closed and Opened events when it does happen (or an Error event if the new connection attempt fails).

    StartAsync()

    Initiates a connection to the SSE server and begins parsing events.

    Declaration
    public Task StartAsync()
    Returns
    Type Description
    Task

    a Task that will be completed only when the EventSource is closed

    Exceptions
    Type Condition
    InvalidOperationException

    if the method was called again after the stream connection was already active

    Events

    Closed

    Occurs when the connection to the EventSource API has been closed.

    Declaration
    public event EventHandler<StateChangedEventArgs> Closed
    Event Type
    Type Description
    EventHandler<StateChangedEventArgs>

    CommentReceived

    Occurs when a comment has been received from the EventSource API.

    Declaration
    public event EventHandler<CommentReceivedEventArgs> CommentReceived
    Event Type
    Type Description
    EventHandler<CommentReceivedEventArgs>

    Error

    Occurs when an error has happened when the EventSource is open and processing Server Sent Events.

    Declaration
    public event EventHandler<ExceptionEventArgs> Error
    Event Type
    Type Description
    EventHandler<ExceptionEventArgs>

    MessageReceived

    Occurs when a Server Sent Event from the EventSource API has been received.

    Declaration
    public event EventHandler<MessageReceivedEventArgs> MessageReceived
    Event Type
    Type Description
    EventHandler<MessageReceivedEventArgs>

    Opened

    Occurs when the connection to the EventSource API has been opened.

    Declaration
    public event EventHandler<StateChangedEventArgs> Opened
    Event Type
    Type Description
    EventHandler<StateChangedEventArgs>

    Implements

    IEventSource
    IDisposable
    In this article
    Back to top Generated by DocFX