# ObserverManager&lt;TIdentity, TObserver&gt; Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/)

## Clear {#clear-d74a08f5}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/clear-d74a08f5/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L100-L102)

```csharp
public void ObserverManager<TIdentity, Clear()
```

Removes all observers.

## ClearExpired {#clearexpired-ef23d468}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/clearexpired-ef23d468/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L251-L268)

```csharp
public void ObserverManager<TIdentity, ClearExpired()
```

Removed all expired observers.

## GetEnumerator {#getenumerator-4c25ac37}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/getenumerator-4c25ac37/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L291)

```csharp
public IEnumerator<TObserver> ObserverManager<TIdentity, GetEnumerator()
```

Returns an enumerator that iterates through the collection.

### Returns

A `System.Collections.Generic.IEnumerator-1` that can be used to iterate through the collection.

## Notify(Func&lt;TObserver, Task&gt;, Func&lt;TObserver, bool&gt;) {#notify-system-func-tobserver-system-threading-tasks-task-system-func-tobserver-b-9d109646}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/notify-system-func-tobserver-system-threading-tasks-task-system-func-tobserver-b-9d109646/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L209-L244)

```csharp
public Task ObserverManager<TIdentity, Notify(Func<TObserver, Task> notification, Func<TObserver, bool>? predicate = null)
```

Notifies all observers.

### Parameters

- `notification` (`Func<TObserver, Task>`): The notification delegate to call on each observer.
- `predicate` (`Func<TObserver, bool>`): The predicate used to select observers to notify.

### Returns

A `System.Threading.Tasks.Task` representing the work performed.

## Notify(Action&lt;TObserver&gt;, Func&lt;TObserver, bool&gt;) {#notify-system-action-tobserver-system-func-tobserver-bool-nullable-f2cba9b4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/notify-system-action-tobserver-system-func-tobserver-bool-nullable-f2cba9b4/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L209-L244)

```csharp
public void ObserverManager<TIdentity, Notify(Action<TObserver> notification, Func<TObserver, bool>? predicate = null)
```

Notifies all observers which match the provided `predicate`.

### Parameters

- `notification` (`Action<TObserver>`): The notification delegate to call on each observer.
- `predicate` (`Func<TObserver, bool>`): The predicate used to select observers to notify.

## Subscribe(TIdentity, TObserver) {#subscribe-tidentity-tobserver-aabc0f6d}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/subscribe-tidentity-tobserver-aabc0f6d/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L116-L131)

```csharp
public void ObserverManager<TIdentity, Subscribe(TIdentity id, TObserver observer)
```

Ensures that the provided `observer` is subscribed, renewing its subscription.

### Parameters

- `id` (`TIdentity`): The observer's identity.
- `observer` (`TObserver`): The observer.

### Exceptions

- `System.Exception`: A delegate callback throws an exception.

## Unsubscribe(TIdentity) {#unsubscribe-tidentity-67a346fc}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.utilities.observermanager-2/methods/unsubscribe-tidentity-67a346fc/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Utils/ObserverManager.cs#L141-L145)

```csharp
public void ObserverManager<TIdentity, Unsubscribe(TIdentity id)
```

Ensures that the provided `id` is unsubscribed.

### Parameters

- `id` (`TIdentity`): The observer.
