Skip to content

If do you want do add one Timer Listening during on current thread of your application, this class auxiliate this job. TimerListen class has a decople code that can be used with asynchrnouly or synchronouly with User Interface

License

Notifications You must be signed in to change notification settings

antonio-leonardo/TimerListen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

C# Timer Listen

If do you want do add one Timer Listening during on current thread of your application, this class auxiliate this job. TimerListen class has a decople code that can be used with asynchronously or synchronously (by SynchronizationContext) with User Interface.

The approach is very simple: define on method that needs to be executed frequently (for example, between one-one second steps or ten-and-ten seconds steps etc.), like bellow:

public static void MethodToExecuteFrequently()
{
   System.Windows.Forms.MessageBox.Show("Ends cycle of timer!");
}

The instance of TimerListen is define as a field class:

public static TimerListen listening = new TimerListen(1000, new Action(() => MethodToExecuteFrequently()))

The developer can instance with sychronized a UI Thread:

//This object was assigned at UI layer:
SynchronizationContext uiThread = SynchronizationContext.Current;

//The TimerListen object with parameters, including the threadContext:
public static TimerListen listening = new TimerListen(1000, new Tuple<Action, SynchronizationContext>(
   ()=>Method, uiThread));

And define the starts and the end of listening:

static void Main()
{
  listening.Start();
  //Batch and long processing to be execute...
  listening.Stop();
}

Concept

The Timer Listen class enjoys features of .NET Framework Timer class, that has a pooling thread, based on Rounding Robing Scheduling


License

View MIT license

About

If do you want do add one Timer Listening during on current thread of your application, this class auxiliate this job. TimerListen class has a decople code that can be used with asynchrnouly or synchronouly with User Interface

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages