我正在創建一個Windows服務,它控制一堆其他進程,但需要內部進程運行到自己的計劃。 每個日程安排都相對簡單,只需選擇一週中的哪幾天運行,何時應該啓動以及何時應該停止。如何排序多維詞典的內部價值
我的想法是有多方面的字典,如下面
Dictionary<string, TimeSpan> OnOff = new Dictionary<string,TimeSpan>();
OnOff.Add("Start", TimeSpan.Parse("09:00"));
OnOff.Add("Stop", TimeSpan.Parse("17:00"));
Dictionary<string, Dictionary<string, TimeSpan>> Process = new Dictionary<string,Dictionary<string,TimeSpan>>();
Process.Add("Process1", OnOff);
Dictionary<DayOfWeek, Dictionary<string, Dictionary<string, TimeSpan>>> schedule = new Dictionary<DayOfWeek,Dictionary<string,Dictionary<string,TimeSpan>>>();
schedule.Add(DayOfWeek.Monday, Process);
並進行排序由最近的「開關機」的時間跨度的「過程」字典使用一個簡單的定時器作用於下一個動作之前用於TimeSpan到達時的過程。
我對這個計劃的問題是TimeSpans的排序,並找到哪個「開始」/「停止」操作包含最接近的TimeSpan進行排序。此外,它可能是包含最接近的TimeSpan的每個流程的不同操作。
或者任何人都可以想到一個簡單的方法來實現相同類型的結果嗎?
我很欣賞有不同的方式來存儲數據 - 如在類/結構,但存在的問題仍然不必爲星期幾的數據和賬戶進行排序的。 – David
您可以定期運行排序函數/算法,並將進程存儲在索引中運行 – Moiz
對不起,它只是發生在我身上,而不是僅僅保留ProcessInfo,您應該保留processInfo的**數組**,並且如果要按類型排序數組使用簡單的排序算法。 – Moiz