Skip to content

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

License

Notifications You must be signed in to change notification settings

sapurtcomputer30/Timeout.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Timeout.Net

This class is very easy to use Just add it to your project And then

   using Timeout.Net

1.Create an instance of the TimeoutContext class

    TimeoutContext<string, string> ctx = new TimeoutContext<string, string>();

2.Add Timeout Context Event Handllers

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

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

Scedule a Action or Code Example

   TimeoutContext<Action, object> timeout = new TimeoutContext<Action, object>();


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));

Releases

No releases published

Packages

No packages published

Languages