An open API service indexing awesome lists of open source software.

https://github.com/imrostami/timeout.net

Simple Multi Thread Timeout class library for .net To implement Timeout feature in .Net
https://github.com/imrostami/timeout.net

csharp csharp-code csharp-library dotnet multithreading task-scheduler timeout timeout-control timeout-library timeout-service

Last synced: about 2 months ago
JSON representation

Simple Multi Thread Timeout class library for .net To implement Timeout feature in .Net

Awesome Lists containing this project

README

        

# Timeout.Net
This class is very easy to use
Just add it to your project
And then

```csharp
using Timeout.Net
```

1.Create an instance of the TimeoutContext class

```csharp
TimeoutContext ctx = new TimeoutContext();
```

2.Add Timeout Context Event Handllers

```csharp
timeout.OnItemScheduled += timeout_OnKeyAdded;
timeout.OnScheduledItemExpired += timeout_OnKeyExpier;

void timeout_OnKeyExpier(string key)
{
Console.WriteLine($"Key {key} Expierd");
}

void timeout_OnKeyAdded(string key)
{
Console.WriteLine($"Key {key} Added");
}
```

Scedule a Key Value

```csharp
//this code scedule a string key for 10 seccend
timeout.SetTimeout("key" , new TimeSpan(hours: 0, 0, 10))
```

Scedule a Action or Code Example

```csharp
TimeoutContext timeout = new TimeoutContext();

timeout.SetTimeout(() =>
{
Console.WriteLine("10 seccend task timeouted");
}, null, new TimeSpan(hours: 0, 0, 10));

timeout.SetTimeout(() =>
{
Console.WriteLine("15 seccend task timeouted");
}, null, new TimeSpan(hours: 0, 0, 15));

```