# Grain Methods

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

## OnActivateAsync(CancellationToken) {#onactivateasync-system-threading-cancellationtoken-2a82a54c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grain/methods/onactivateasync-system-threading-cancellationtoken-2a82a54c/)

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

```csharp
public virtual Task OnActivateAsync(CancellationToken cancellationToken)
```

This method is called at the end of the process of activating a grain. It is called before any messages have been dispatched to the grain. For grains with declared persistent state, this method is called after the State property has been populated.

### Parameters

- `cancellationToken` (`CancellationToken`): A cancellation token which signals when activation is being canceled.

## OnDeactivateAsync(DeactivationReason, CancellationToken) {#ondeactivateasync-orleans-deactivationreason-system-threading-cancellationtoken-43c948de}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grain/methods/ondeactivateasync-orleans-deactivationreason-system-threading-cancellationtoken-43c948de/)

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

```csharp
public virtual Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
```

This method is called at the beginning of the process of deactivating a grain.

### Parameters

- `reason` (`DeactivationReason`): The reason for deactivation. Informational only.
- `cancellationToken` (`CancellationToken`): A cancellation token which signals when deactivation should complete promptly.
