# Utils Methods

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

## AverageTicksToMilliSeconds(float) {#averagetickstomilliseconds-float-09737fe8}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/averagetickstomilliseconds-float-09737fe8/)

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

```csharp
public static float AverageTicksToMilliSeconds(float ticks)
```

### Parameters

- `ticks` (`float`)

## BatchIEnumerable(IEnumerable&lt;T&gt;, int) {#batchienumerable-1-this-system-collections-generic-ienumerable-t-int-3cedc8a8}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/batchienumerable-1-this-system-collections-generic-ienumerable-t-int-3cedc8a8/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L212-L227)

```csharp
public static IEnumerable<List<T>> BatchIEnumerable<T>(this IEnumerable<T> sequence, int batchSize)
```

### Parameters

- `sequence` (`IEnumerable<T>`)
- `batchSize` (`int`)

## DictionaryToString(ICollection&lt;KeyValuePair&lt;T1, T2&gt;&gt;, Func&lt;T2, string?&gt;, string?) {#dictionarytostring-2-system-collections-generic-icollection-system-collections-g-0bdacd1a}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/dictionarytostring-2-system-collections-generic-icollection-system-collections-g-0bdacd1a/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L83-L113)

```csharp
public static string DictionaryToString<T1, T2>(ICollection<KeyValuePair<T1, T2>> dict, Func<T2, string?>? toString = null, string? separator = null)
```

Returns a human-readable text string that describes a dictionary that maps objects to objects.

### Parameters

- `dict` (`ICollection<KeyValuePair<T1, T2>>`): The dictionary to describe.
- `toString` (`Func<T2, string?>`): Converts the element to a string. If none specified, `System.Object.ToString` will be used.
- `separator` (`string?`): The separator to use. If none specified, the elements should appear separated by a new line.

### Returns

A string assembled by wrapping the string descriptions of the individual pairs with square brackets and separating them with commas. Each key-value pair is represented as the string description of the key followed by the string description of the value, separated by " -&gt; ", and enclosed in curly brackets.

## EnumerableToString(IEnumerable&lt;T&gt;, Func&lt;T, string&gt;, string, bool) {#enumerabletostring-1-system-collections-generic-ienumerable-t-nullable-system-fu-28575942}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/enumerabletostring-1-system-collections-generic-ienumerable-t-nullable-system-fu-28575942/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L29-L65)

```csharp
public static string EnumerableToString<T>(IEnumerable<T>? collection, Func<T, string>? toString = null, string separator = ", ", bool putInBrackets = true)
```

Returns a human-readable text string that describes an IEnumerable collection of objects.

### Parameters

- `collection` (`IEnumerable<T>`): The IEnumerable to describe.
- `toString` (`Func<T, string>`): Converts the element to a string. If none specified, `System.Object.ToString` will be used.
- `separator` (`string`): The separator to use.
- `putInBrackets` (`bool`): Puts elements within brackets

### Returns

A string assembled by wrapping the string descriptions of the individual elements with square brackets and separating them with commas.

## GetStackTrace(int) {#getstacktrace-int-9bb70e01}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/getstacktrace-int-9bb70e01/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L232-L233)

```csharp
public static string GetStackTrace(int skipFrames = 0)
```

### Parameters

- `skipFrames` (`int`)

## SafeExecute(Action) {#safeexecute-system-action-3c872b1a}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/safeexecute-system-action-3c872b1a/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L165-L168)

```csharp
public static void SafeExecute(Action action)
```

### Parameters

- `action` (`Action`)

## SafeExecute(Action, ILogger?, string?) {#safeexecute-system-action-microsoft-extensions-logging-ilogger-nullable-string-n-1ef3c3dd}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/safeexecute-system-action-microsoft-extensions-logging-ilogger-nullable-string-n-1ef3c3dd/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L174-L181)

```csharp
public static void SafeExecute(Action action, ILogger? logger = null, string? caller = null)
```

### Parameters

- `action` (`Action`)
- `logger` (`ILogger?`)
- `caller` (`string?`)

## SafeExecuteAsync(Task) {#safeexecuteasync-system-threading-tasks-task-e008a4d9}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/safeexecuteasync-system-threading-tasks-task-e008a4d9/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Utils/Utils.cs#L187-L190)

```csharp
public static Task SafeExecuteAsync(Task task)
```

### Parameters

- `task` (`Task`)

## TicksToMilliSeconds(long) {#tickstomilliseconds-long-0a5777c9}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/tickstomilliseconds-long-0a5777c9/)

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

```csharp
public static long TicksToMilliSeconds(long ticks)
```

### Parameters

- `ticks` (`long`)

## TimeSpanToString(TimeSpan) {#timespantostring-system-timespan-11af98e6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/timespantostring-system-timespan-11af98e6/)

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

```csharp
public static string TimeSpanToString(TimeSpan timeSpan)
```

### Parameters

- `timeSpan` (`TimeSpan`)

## ToGatewayAddress(Uri) {#togatewayaddress-this-system-uri-ea7f4633}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/togatewayaddress-this-system-uri-ea7f4633/)

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

```csharp
public static SiloAddress? ToGatewayAddress(this Uri uri)
```

Parse a Uri as a Silo address, excluding the generation identifier.

### Parameters

- `uri` (`Uri`): The input Uri

## ToGatewayUri(IPEndPoint) {#togatewayuri-this-system-net-ipendpoint-d2f0be4c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/togatewayuri-this-system-net-ipendpoint-d2f0be4c/)

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

```csharp
public static Uri ToGatewayUri(this IPEndPoint ep)
```

Represent an IP end point in the gateway URI format..

### Parameters

- `ep` (`IPEndPoint`): The input IP end point

## ToGatewayUri(SiloAddress) {#togatewayuri-this-orleans-runtime-siloaddress-1844ec5e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/togatewayuri-this-orleans-runtime-siloaddress-1844ec5e/)

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

```csharp
public static Uri ToGatewayUri(this SiloAddress address)
```

Represent a silo address in the gateway URI format.

### Parameters

- `address` (`SiloAddress`): The input silo address

## ToIPEndPoint(Uri) {#toipendpoint-this-system-uri-2d22627a}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.utils/methods/toipendpoint-this-system-uri-2d22627a/)

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

```csharp
public static IPEndPoint? ToIPEndPoint(this Uri uri)
```

Parse a Uri as an IPEndpoint.

### Parameters

- `uri` (`Uri`): The input Uri
