コード例 #1
0
        public static void StartReading(ReadingType rType)
        {
            foreach (Task task in tasks)
            {
                //Start the thread
                task.Start();
                try
                {
                    task.Wait();
                }
                catch { }
                Thread.Sleep(100);
            }

            Task t = Task.WhenAll(tasks);

            try
            {
                t.Wait();
            }
            catch { }

            //TODO Move this code to higher level
            if (t.IsCompleted)
            {
                string query = "";
                switch (rType)
                {
                case ReadingType.Hourly:
                {
                    query += DBManager.AssembleTableQuery("tblwatermeters1h");
                }
                break;

                case ReadingType.Daily:
                {
                    query += DBManager.AssembleTableQuery("tblwatermeters1h");
                    query += DBManager.AssembleTableQuery("tblwatermeters");
                }
                break;

                default:
                    throw new NotImplementedException($"Type '{rType.ToString()}' not implemented.");
                }

                //Execute the query
                DBManager db = new DBManager();
                db.Execute(query);
                Output.Report("Database updated.");

                //TODO Add database cleanup
                db.Disconnect();

                //Release resources
                foreach (Task task in tasks)
                {
                    task.Dispose();
                }
                t.Dispose();
            }
        }