# GrainBaseExtensions Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/)

## DeactivateOnIdle(IGrainBase) {#deactivateonidle-this-orleans-igrainbase-39cd40ea}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/deactivateonidle-this-orleans-igrainbase-39cd40ea/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs#L47)

```csharp
public static void DeactivateOnIdle(this IGrainBase grain)
```

Deactivate this grain activation after the current grain method call is completed. This call will mark this activation of the current grain to be deactivated and removed at the end of the current method. The next call to this grain will result in a different activation to be used, which typical means a new activation will be created automatically by the runtime.

### Parameters

- `grain` (`IGrainBase`)

## MigrateOnIdle(IGrainBase) {#migrateonidle-this-orleans-igrainbase-d62d28e3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/migrateonidle-this-orleans-igrainbase-d62d28e3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs#L54)

```csharp
public static void MigrateOnIdle(this IGrainBase grain)
```

Starts an attempt to migrating this instance to another location. Migration captures the current [RequestContext](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.requestcontext/), making it available to the activation's placement director so that it can consider it when selecting a new location. Migration will occur asynchronously, when no requests are executing, and will not occur if the activation's placement director does not select an alternative location.

### Parameters

- `grain` (`IGrainBase`)

## RegisterGrainTimer(IGrainBase, Func&lt;CancellationToken, Task&gt;, GrainTimerCreationOptions) {#registergraintimer-this-orleans-igrainbase-system-func-system-threading-cancella-10b2ade8}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-this-orleans-igrainbase-system-func-system-threading-cancella-10b2ade8/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, GrainTimerCreationOptions options)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`): The grain instance.
- `callback` (`Func<CancellationToken, Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `options` (`GrainTimerCreationOptions`): The options for creating the timer.

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.

## RegisterGrainTimer(IGrainBase, Func&lt;CancellationToken, Task&gt;, TimeSpan, TimeSpan) {#registergraintimer-this-orleans-igrainbase-system-func-system-threading-cancella-35aa6fb9}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-this-orleans-igrainbase-system-func-system-threading-cancella-35aa6fb9/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, TimeSpan dueTime, TimeSpan period)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`): The grain instance.
- `callback` (`Func<CancellationToken, Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `dueTime` (`TimeSpan`): A `System.TimeSpan` representing the amount of time to delay before invoking the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to prevent the timer from starting. Specify `System.TimeSpan.Zero` to start the timer immediately.
- `period` (`TimeSpan`): The time interval between invocations of the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to disable periodic signaling.

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.

## RegisterGrainTimer(IGrainBase, Func&lt;Task&gt;, GrainTimerCreationOptions) {#registergraintimer-this-orleans-igrainbase-system-func-system-threading-tasks-ta-76343590}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-this-orleans-igrainbase-system-func-system-threading-tasks-ta-76343590/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<Task> callback, GrainTimerCreationOptions options)
```

### Parameters

- `grain` (`IGrainBase`)
- `callback` (`Func<Task>`)
- `options` (`GrainTimerCreationOptions`)

## RegisterGrainTimer(IGrainBase, Func&lt;Task&gt;, TimeSpan, TimeSpan) {#registergraintimer-this-orleans-igrainbase-system-func-system-threading-tasks-ta-bec417a1}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-this-orleans-igrainbase-system-func-system-threading-tasks-ta-bec417a1/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<Task> callback, TimeSpan dueTime, TimeSpan period)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`): The grain instance.
- `callback` (`Func<Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `dueTime` (`TimeSpan`): A `System.TimeSpan` representing the amount of time to delay before invoking the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to prevent the timer from starting. Specify `System.TimeSpan.Zero` to start the timer immediately.
- `period` (`TimeSpan`): The time interval between invocations of the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to disable periodic signaling.

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.

## RegisterGrainTimer(IGrainBase, Func&lt;TState, CancellationToken, Task&gt;, TState, GrainTimerCreationOptions) {#registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-392e96ae}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-392e96ae/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, GrainTimerCreationOptions options)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`)
- `callback` (`Func<TState, CancellationToken, Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `state` (`TState`): The state passed to the callback.
- `options` (`GrainTimerCreationOptions`): The options for creating the timer.

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.

## RegisterGrainTimer(IGrainBase, Func&lt;TState, CancellationToken, Task&gt;, TState, TimeSpan, TimeSpan) {#registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-b59b5d77}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-b59b5d77/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`): The grain instance.
- `callback` (`Func<TState, CancellationToken, Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `state` (`TState`): The state passed to the callback.
- `dueTime` (`TimeSpan`): The time interval between invocations of the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to disable periodic signaling.
- `period` (`TimeSpan`)

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.

## RegisterGrainTimer(IGrainBase, Func&lt;TState, Task&gt;, TState, GrainTimerCreationOptions) {#registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-8069edf2}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-8069edf2/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, Task> callback, TState state, GrainTimerCreationOptions options)
```

### Parameters

- `grain` (`IGrainBase`)
- `callback` (`Func<TState, Task>`)
- `state` (`TState`): The state passed to the callback.
- `options` (`GrainTimerCreationOptions`)

## RegisterGrainTimer(IGrainBase, Func&lt;TState, Task&gt;, TState, TimeSpan, TimeSpan) {#registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-41273f23}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainbaseextensions/methods/registergraintimer-1-this-orleans-igrainbase-system-func-tstate-system-threading-41273f23/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainBase.cs)

```csharp
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
```

Creates a grain timer.

### Parameters

- `grain` (`IGrainBase`): The grain instance.
- `callback` (`Func<TState, Task>`): The timer callback, which will be invoked whenever the timer becomes due.
- `state` (`TState`): The state passed to the callback.
- `dueTime` (`TimeSpan`): The time interval between invocations of the callback method specified when the [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) was constructed. Specify `System.Threading.Timeout.InfiniteTimeSpan` to disable periodic signaling.
- `period` (`TimeSpan`)

### Returns

The [IGrainTimer](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.igraintimer/) instance which represents the timer.
