Skip to content

Commit

Permalink
Prevent the user from refreshing the server status too often. (10 sec…
Browse files Browse the repository at this point in the history
…onds until the refresh button becomes available again)
  • Loading branch information
FelisDiligens committed Sep 2, 2022
1 parent 9bbe39c commit a9c6d6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Fo76ini/Forms/FormMain/Views/UserControlHome.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Fo76ini/Forms/FormMain/Views/UserControlHome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand Down Expand Up @@ -323,6 +324,12 @@ private void LoadServerStatus()
this.backgroundWorkerScrapeServerStatus.RunWorkerAsync();
}

private void timerReenableRefreshServerStatus_Tick(object sender, EventArgs e)
{
this.buttonReloadServerStatus.Enabled = true;
this.timerReenableRefreshServerStatus.Stop();
}

private void buttonReloadServerStatus_Click(object sender, EventArgs e)
{
LoadServerStatus();
Expand Down Expand Up @@ -354,6 +361,8 @@ private void backgroundWorkerScrapeServerStatus_DoWork(object sender, DoWorkEven
}

e.Result = status;

Thread.Sleep(500); // Sneak in a little delay, so the user doesn't think that it's broken.
}

private void backgroundWorkerScrapeServerStatus_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand All @@ -362,7 +371,7 @@ private void backgroundWorkerScrapeServerStatus_RunWorkerCompleted(object sender
this.labelScrapedServerStatus.Text = status.localizedStatus;
this.pictureBoxScrapedServerStatus.Image = status.image;
this.buttonReloadServerStatus.Left = this.labelScrapedServerStatus.Left + this.labelScrapedServerStatus.Width + 6;
this.buttonReloadServerStatus.Enabled = true;
this.timerReenableRefreshServerStatus.Start();
}

// Helper struct for the Background Worker.
Expand Down
3 changes: 3 additions & 0 deletions Fo76ini/Forms/FormMain/Views/UserControlHome.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<metadata name="backgroundWorkerScrapeServerStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>266, 17</value>
</metadata>
<metadata name="timerReenableRefreshServerStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>527, 17</value>
</metadata>
</root>

0 comments on commit a9c6d6b

Please sign in to comment.