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
- Host: GitHub
- URL: https://github.com/imrostami/timeout.net
- Owner: imrostami
- License: gpl-3.0
- Created: 2023-02-04T19:18:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-04T18:36:37.000Z (almost 2 years ago)
- Last Synced: 2025-03-31T10:04:21.981Z (3 months ago)
- Topics: csharp, csharp-code, csharp-library, dotnet, multithreading, task-scheduler, timeout, timeout-control, timeout-library, timeout-service
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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));```