private static void Count() { Task t = Task.Factory.StartNew(() => { while (true) { Thread.Sleep(1000); if (readyToCount) { double value = 0; double panelPom2 = panelPom; double consumerPom2 = consumerPom; double batteryPom2 = batteryPom; lock (obj) { Program.readyToCount = false; panelPom = 0; consumerPom = 0; batteryPom = 0; } if (state == States.ISKLJUCENA) { value = panelPom2 - consumerPom2; price = proxyUtility.CalculateMoney(value); } else if (state == States.PRAZNJENJE) { value = panelPom2 + batteryPom2 - consumerPom2; price = proxyUtility.CalculateMoney(value); } else { value = panelPom2 - batteryPom2 - consumerPom2; price = proxyUtility.CalculateMoney(value); } //*************************************************************************************** //UPIS u Bazu PerformDatabaseOperations(batteryPom2, panelPom2, consumerPom2, price); Console.WriteLine("Trenutna cena je: " + price); } } }); }