static TagProcessing() { dataKeyId = 0; db = DataManipulator.loadData(); //vidi sta se desava kada korisnik doda tag AItags = new Dictionary <string, AI>(); DItags = new Dictionary <string, DI>(); AIthreads = new Dictionary <string, Thread>(); DIthreads = new Dictionary <string, Thread>(); trending = new TrendingService(); alarming = new AlarmDisplayService(); foreach (AI ai in db.AIs) { AItags.Add(ai.Id, ai); AIthreads.Add(ai.Id, new Thread(() => readAI(ai.Id))); } foreach (DI di in db.DIs) { DItags.Add(di.Id, di); DIthreads.Add(di.Id, new Thread(() => readDI(di.Id))); } //start threads foreach (Thread t in AIthreads.Values) { t.Start(); } foreach (Thread t in DIthreads.Values) { t.Start(); } Thread saveThread = new Thread(() => { while (true) { lock (db) { db.SaveChanges(); } Thread.Sleep(10000); } }); saveThread.Start(); }