private void Global_SendMetricsToServer(object sender, EventArgs e) { // Send Metrics to Server if (Global.sending_metrics) { if (METRICS_ENABLED) { FreeNetworkThreads(); Thread connectionTestThread = new Thread(() => MetricsHandler.test_connection()); connectionTestThread.Name = "Testing network connection"; connectionTestThread.Start(); MetricsThreads.Add(connectionTestThread); FreeNetworkThreads(); lock (MetricsLock) // Tested again here, in case it was turned off between entering the if and getting control of the lock if (Global.sending_metrics) { Thread metricsThread = new Thread(() => SendMetricsToServer(Global.metrics_data, Global.metrics_gameplay_data)); metricsThread.Name = "Sending metrics"; metricsThread.Start(); MetricsThreads.Add(metricsThread); } } else { Global.metrics_sent(false); } } }
private void SendMetricsToServer(string query, string post) { Thread.Sleep(10); TactileLibrary.Maybe <bool> result = TactileLibrary.Maybe <bool> .Nothing; #if WINDOWS || MONOMAC // Tries to send the metrics METRICS_SENDING_ATTEMPTS times; stops if any attempt succeeds for (int i = 0; i < METRICS_SENDING_ATTEMPTS && result.IsNothing; i++) { result = MetricsHandler.send_data(query, post); if (result.IsNothing) { Thread.Sleep(10); } } #if DEBUG Debug.Assert(result.IsSomething, string.Format("Metrics sending failed after {0} attempts.", METRICS_SENDING_ATTEMPTS)); Debug.Assert(result.IsNothing || result.ValueOrDefault, "Metrics sending succeeded, but the data was invalid"); #endif #endif lock (MetricsLock) Global.metrics_sent(result.ValueOrDefault); }