Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void RefreshConnect()
- {
- new System.Timers.Timer(1000) { Enabled = true }.Elapsed += delegate
- {
- var connected = CheckNet.CheckURL(StrSite.TestConnect);
- while(connected)
- if (connected)
- {
- CheckProcessClose.Enabled = true;
- OffSite4Game.Enabled = true;
- TracePing.Enabled = true;
- Checker4Game.Enabled = true;
- OffSiteForum.Enabled = true;
- SupportGame.Enabled = true;
- MRTDownload.Enabled = true;
- }
- else
- {
- CheckProcessClose.Enabled = false;
- OffSite4Game.Enabled = false;
- TracePing.Enabled = false;
- Checker4Game.Enabled = false;
- OffSiteForum.Enabled = false;
- SupportGame.Enabled = false;
- MRTDownload.Enabled = false;
- Refresh();
- }
- Invoke(new MethodInvoker(() => { BadConnect.Visible = !connected; }));
- };
- }
- Task.Factory.StartNew(() => RefreshConnect());
- class ConnectionMonitor : IDisposable
- {
- private bool urlAvailable = false;
- private bool isActive = false;
- private System.Threading.Timer timer;
- public string Url { get; private set; }
- public event EventHandler ConnectionStateChanged;
- public ConnectionMonitor(string checkingUrl) { Url = checkingUrl; }
- public void Start()
- {
- isActive = true;
- timer = new Timer(CheckUrl, null, 1000, Timeout.Infinite);
- }
- public void Stop()
- {
- isActive = false;
- }
- private void CheckUrl(object state)//сигнатура для TimerCalback
- {
- var checkResult = CheckNet.CheckURL(StrSite.TestConnect);
- if(checkResult ^ urlAvailable)
- {
- ConnectionStateChanged.Invoke(this, new EventArgs());
- urlAvailable = checkResult;
- }
- timer.Dispose();
- if(isActive)
- timer = new Timer(CheckUrl, null, 1000, Timeout.Infinite);
- }
- public void Dispose() { timer?.Dispose(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement