開発に使用するリポジトリ
Revisión | 4f2d60256d02255bf58d797b7eea9a5f86a244a8 (tree) |
---|---|
Tiempo | 2013-01-19 20:21:04 |
Autor | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
img.azyobuzi.net 正規表現の更新にSystem.Therading.Timerを使用
@@ -22,25 +22,22 @@ | ||
22 | 22 | using System; |
23 | 23 | using System.Collections.Generic; |
24 | 24 | using System.Linq; |
25 | -using System.Text; | |
26 | 25 | using System.Net; |
27 | 26 | using System.Runtime.Serialization.Json; |
28 | 27 | using System.Xml; |
29 | 28 | using System.Xml.Linq; |
30 | -using System.Xml.XPath; | |
31 | 29 | using System.Text.RegularExpressions; |
32 | -using System.Threading.Tasks; | |
33 | 30 | using System.Threading; |
34 | -using System.Windows.Forms; | |
35 | 31 | |
36 | 32 | namespace OpenTween.Thumbnail.Services |
37 | 33 | { |
38 | - class ImgAzyobuziNet : IThumbnailService | |
34 | + class ImgAzyobuziNet : IThumbnailService, IDisposable | |
39 | 35 | { |
40 | 36 | protected string[] ApiHosts = { "http://img.azyobuzi.net/api/", "http://img.opentween.org/api/" }; |
41 | 37 | |
42 | 38 | protected string ApiBase; |
43 | 39 | protected IEnumerable<Regex> UrlRegex = new Regex[] {}; |
40 | + protected Timer UpdateTimer; | |
44 | 41 | |
45 | 42 | private object LockObj = new object(); |
46 | 43 |
@@ -48,20 +45,33 @@ namespace OpenTween.Thumbnail.Services | ||
48 | 45 | { |
49 | 46 | this.LoadRegex(); |
50 | 47 | |
51 | - if (autoupdate) | |
52 | - this.StartAutoUpdate(); | |
48 | + this.UpdateTimer = new Timer(_ => this.LoadRegex()); | |
49 | + this.AutoUpdate = autoupdate; | |
53 | 50 | } |
54 | 51 | |
55 | - public void StartAutoUpdate() | |
52 | + public bool AutoUpdate | |
56 | 53 | { |
57 | - Task.Factory.StartNew(() => | |
54 | + get { return this._AutoUpdate; } | |
55 | + set | |
58 | 56 | { |
59 | - for (;;) | |
60 | - { | |
61 | - Thread.Sleep(30 * 60 * 1000); // 30分おきに更新 | |
62 | - this.LoadRegex(); | |
63 | - } | |
64 | - }, TaskCreationOptions.LongRunning); | |
57 | + if (value) | |
58 | + this.StartAutoUpdate(); | |
59 | + else | |
60 | + this.StopAutoUpdate(); | |
61 | + | |
62 | + this._AutoUpdate = value; | |
63 | + } | |
64 | + } | |
65 | + private bool _AutoUpdate = false; | |
66 | + | |
67 | + protected void StartAutoUpdate() | |
68 | + { | |
69 | + this.UpdateTimer.Change(0, 30 * 60 * 1000); ; // 30分おきに更新 | |
70 | + } | |
71 | + | |
72 | + protected void StopAutoUpdate() | |
73 | + { | |
74 | + this.UpdateTimer.Change(Timeout.Infinite, Timeout.Infinite); | |
65 | 75 | } |
66 | 76 | |
67 | 77 | public void LoadRegex() |
@@ -135,5 +145,10 @@ namespace OpenTween.Thumbnail.Services | ||
135 | 145 | |
136 | 146 | return null; |
137 | 147 | } |
148 | + | |
149 | + public virtual void Dispose() | |
150 | + { | |
151 | + this.UpdateTimer.Dispose(); | |
152 | + } | |
138 | 153 | } |
139 | 154 | } |