public void Mining(VideoCard card, LocalCurrency lc, bool flag) { if (flag) { if (treads.ContainsKey(card)) { return; } Thread th = new Thread(() => Work(card, lc)); th.IsBackground = true; th.Start(); treads.Add(card, th); card.ActiveTasks++; } else { if (!treads.ContainsKey(card)) { return; } Thread th = treads[card]; treads.Remove(card); th.Abort(); card.ActiveTasks--; } }
void StartAbortMining(VideoCard card, LocalCurrency lc, bool flag) { GlobalCurrency activeCur = Currencies.FirstOrDefault(curr => curr.Id == lc.Id); if (activeCur == null) { return; } activeCur.Mining(card, lc, flag); }
void Work(VideoCard card, LocalCurrency lc) { while (true) { Thread.Sleep(1000); double v = card.Power / card.ActiveTasks / diff / 100000000; lock (locker) { Val += v; } lc.Val += v; } }
public void RemoveCurr(Guid id) { LocalCurrency lc = Currencies.FirstOrDefault(c => c.Id == id); if (lc != null) { if (lc.IsAct) { ActiveTasks--; } Currencies.Remove(lc); } }
void AddRemTask(LocalCurrency lc, bool flag) { startAbortMining(this, lc, flag); }