-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathAutoRefreshExtension.cs
42 lines (37 loc) · 1.14 KB
/
AutoRefreshExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Threading.Tasks;
using System.Timers;
namespace RingCentral.Net.AutoRefresh
{
public class AutoRefreshExtension : SdkExtension
{
private readonly AutoRefreshOptions _options;
private Timer _autoRefreshTimer;
private RestClient _rc;
public AutoRefreshExtension(AutoRefreshOptions autoRefreshOptions = null)
{
_options = autoRefreshOptions ?? AutoRefreshOptions.DefaultInstance;
}
public override Task Install(RestClient rc)
{
_rc = rc;
return Task.CompletedTask;
}
public void Start()
{
Stop(); // stop existing
_autoRefreshTimer = new Timer();
_autoRefreshTimer.Elapsed += (sender, args) => { _rc.Refresh(); };
_autoRefreshTimer.Interval = _options.interval;
_autoRefreshTimer.Start();
}
public void Stop()
{
if (_autoRefreshTimer != null)
{
_autoRefreshTimer.Stop();
_autoRefreshTimer.Dispose();
_autoRefreshTimer = null;
}
}
}
}