private static void SyncThread() { try { _running = 1; //mainForm.LogLine("Starting EDDN sync thread"); while (hlscanunsyncedlist.Count != 0) { List <HistoryEntry> hl = new List <HistoryEntry>(); HistoryEntry he = null; int eventcount = 0; while (hlscanunsyncedlist.TryDequeue(out he)) { hlscanevent.Reset(); TimeSpan age = he.AgeOfEntry(); if (age.Days >= 1 && he.EntryType != EliteDangerousCore.JournalTypeEnum.Scan) { System.Diagnostics.Debug.WriteLine("EDDN: Ignoring entry due to age"); } else if (EDDNSync.SendToEDDN(he)) { logger?.Invoke($"Sent {he.EntryType.ToString()} event to EDDN ({he.EventSummary})"); eventcount++; } if (Exit) { return; } Thread.Sleep(1000); // Throttling to 1 per second to not kill EDDN network } SentEvents?.Invoke(eventcount); // tell the system.. if (hlscanunsyncedlist.IsEmpty) // if nothing there.. { hlscanevent.WaitOne(60000); // Wait up to 60 seconds for another EDDN event to come in } if (Exit) { return; } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); logger?.Invoke("EDDN sync Exception " + ex.Message); } finally { _running = 0; } }
private static void SyncThread() { running = 1; //mainForm.LogLine("Starting EDDN sync thread"); while (hlscanunsyncedlist.Count != 0) { HistoryEntry he = null; int eventcount = 0; while (hlscanunsyncedlist.TryDequeue(out he)) { try { hlscanevent.Reset(); TimeSpan age = he.AgeOfEntry(); if (age.Days >= 1 && he.EntryType != EliteDangerousCore.JournalTypeEnum.Scan) { System.Diagnostics.Debug.WriteLine("EDDN: Ignoring entry due to age"); } else { bool?res = EDDNSync.SendToEDDN(he); if (res != null) // if attempted to send { if (res.Value == true) { logger?.Invoke($"Sent {he.EntryType.ToString()} event to EDDN ({he.EventSummary})"); eventcount++; } else { logger?.Invoke($"Failed sending {he.EntryType.ToString()} event to EDDN ({he.EventSummary})"); } } else { continue; // skip the 1 second delay if nothing was sent } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.StackTrace); logger?.Invoke("EDDN sync Exception " + ex.Message + Environment.NewLine + ex.StackTrace); } if (Exit) { running = 0; return; } Thread.Sleep(1000); // Throttling to 1 per second to not kill EDDN network } SentEvents?.Invoke(eventcount); // tell the system.. if (hlscanunsyncedlist.IsEmpty) // if nothing there.. { hlscanevent.WaitOne(60000); // Wait up to 60 seconds for another EDDN event to come in } if (Exit) { break; } } running = 0; }