diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-08 12:03:06 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-08 12:03:06 +0200 |
| commit | 5da415d6935bd6faa8c49db66f11015a8050bf4d (patch) | |
| tree | d2b124a77b4e46f8c7ea92fa2e15151fe4d0d6e5 /Software/Visual_Studio/Tango.Core/Threading | |
| parent | 65115888c2d2fd03522dd4b5243a6657e15a62f0 (diff) | |
| download | Tango-5da415d6935bd6faa8c49db66f11015a8050bf4d.tar.gz Tango-5da415d6935bd6faa8c49db66f11015a8050bf4d.zip | |
Moved android project and new project.
Visual Studio Timeout Task!
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/Threading')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Threading/TimeoutTask.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Threading/TimeoutTask.cs b/Software/Visual_Studio/Tango.Core/Threading/TimeoutTask.cs new file mode 100644 index 000000000..04edaba85 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Threading/TimeoutTask.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Tango.Core.Threading +{ + /// <summary> + /// Represents a simple task with a delay mechanism. + /// </summary> + public class TimeoutTask + { + private Action _action; + private TimeSpan _timeout; + + /// <summary> + /// Initializes a new instance of the <see cref="TimeoutTask"/> class. + /// </summary> + /// <param name="action">The action.</param> + /// <param name="timeout">The timeout.</param> + public TimeoutTask(Action action, TimeSpan timeout) + { + _action = action; + _timeout = timeout; + } + + /// <summary> + /// Starts the task after the specified timeout. + /// </summary> + public void Start() + { + Thread t = new Thread(() => + { + Thread.Sleep(_timeout); + _action(); + }); + t.IsBackground = true; + t.Start(); + } + + /// <summary> + /// Starts a new <see cref="TimeoutTask"/> with the specified timeout. + /// </summary> + /// <param name="action">The action.</param> + /// <param name="timeout">The timeout.</param> + public static void StartNew(Action action,TimeSpan timeout) + { + new TimeoutTask(action, timeout).Start(); + } + } +} |
