Only Initialize the stat tracker once, and explicitly set timeout to 5 seconds.

This commit is contained in:
Zack Piispanen 2013-11-08 02:20:38 -05:00
parent b2abf89432
commit f4c332ab2f
2 changed files with 15 additions and 4 deletions

View file

@ -11,11 +11,21 @@ namespace TShockAPI
{ {
public class StatTracker public class StatTracker
{ {
private bool failed = false; private bool failed;
private bool initialized;
public StatTracker() public StatTracker()
{ {
}
public void Initialize()
{
if (!initialized)
{
initialized = true;
ThreadPool.QueueUserWorkItem(SendUpdate); ThreadPool.QueueUserWorkItem(SendUpdate);
} }
}
private HttpWebResponse GetResponseNoException(HttpWebRequest req) private HttpWebResponse GetResponseNoException(HttpWebRequest req)
{ {
@ -51,6 +61,7 @@ namespace TShockAPI
var encoded = HttpUtility.UrlEncode(serialized); var encoded = HttpUtility.UrlEncode(serialized);
var uri = String.Format("http://96.47.231.227:8000?data={0}", encoded); var uri = String.Format("http://96.47.231.227:8000?data={0}", encoded);
var client = (HttpWebRequest)WebRequest.Create(uri); var client = (HttpWebRequest)WebRequest.Create(uri);
client.Timeout = 5000;
try try
{ {
using (var resp = GetResponseNoException(client)) using (var resp = GetResponseNoException(client))

View file

@ -70,7 +70,7 @@ namespace TShockAPI
public static SecureRest RestApi; public static SecureRest RestApi;
public static RestManager RestManager; public static RestManager RestManager;
public static Utils Utils = Utils.Instance; public static Utils Utils = Utils.Instance;
public static StatTracker StatTracker; public static StatTracker StatTracker = new StatTracker();
/// <summary> /// <summary>
/// Used for implementing REST Tokens prior to the REST system starting up. /// Used for implementing REST Tokens prior to the REST system starting up.
/// </summary> /// </summary>
@ -599,7 +599,7 @@ namespace TShockAPI
ComputeMaxStyles(); ComputeMaxStyles();
FixChestStacks(); FixChestStacks();
StatTracker = new StatTracker(); StatTracker.Initialize();
} }
private void ComputeMaxStyles() private void ComputeMaxStyles()