I Want to print the number 1 to 6 every 5 sec and stop timer when reaching the end of the list
private static void Main(string[] args) { List<int> l = new List<int>() {1,2,3,4,5,6}; XElement xdoc = XElement.Load("../../XMLFile1.xml"); xdoc.Element("num").Value = "0"; xdoc.Element("max").Value = l.Count.ToString(); xdoc.Save("../../XMLFile1.xml"); Timer t = new Timer(printnum, null, 0, 5000); } public static void printnum(Object o) { try { XElement xdoc = XElement.Load("../../XMLFile1.xml"); int num = int.Parse(xdoc.Element("num").Value); int max = int.Parse(xdoc.Element("max").Value); if (num<max) { Console.WriteLine(num); num += 1; xdoc.Element("num").Value = num.ToString(); xdoc.Save("../../XMLFile1.xml"); } } catch (Exception e) { } } This is my xml file named XMLFile1.xml the num is running number and max is the list max number
<?xml version="1.0" encoding="utf-8"?> <root> <num>0</num> <max>0</max> </root>
No comments:
Post a Comment