No, you don't do it that way.
What happens with a Timer is that you get a Tick event each time the timer gets to the interval specified. In you example, you would get a single Tick event each five seconds.
What you are doing is every time you get a tick, you are outputting the entire document to teh same textbox, line by line, and overwriting it immediately with the next.
You need to change the way you are trying to handle this.
In your code (on a button press, or similar):
1) Create a Class level List<string> and declare it as
private
2) Create your XDocument, and build your query from it.
3) Init your List with a new List<string>
4) Loop through your query results as you are and add each string to the List.
5) Start your Timer.
In the Timer Tick event:
1) Get a single string from the front of the List
2) Remove it from the List so you don't use it again
3) Set the TextBox.Text field to the string.
(You may find that a Queue<string> may be more use to you - but I don't know if you are familiar with queues and related data structures.)
"tried got it , my code is like this
if (_xmlData.Count == 0)
{
counter = 0;
XDocument xd = XDocument.Load(@"D:\satish1\na.xml");
var query = from p in xd.Descendants("item")
select new
{
des = p.Element("description").Value
};
foreach (var p in query)
{
_xmlData.Add(p.des.ToString());
}
}
if (counter < _xmlData.Count)
tbs.Text = _xmlData[counter];
counter++;
if (counter == _xmlData.Count)
{
counter = 0;
}
thanks for ur help"
No, no. You need to separate the initialization code (where you read the XML) from the display code (in the Timer Tick event).
Assuming you press a button to start this going:
private List<string> _xmlData = new List<string>();
private void MyGoButton_Click(object sender, EventArgs e)
{
XDocument xd = XDocument.Load(@"D:\satish1\na.xml");
var query = from p in xd.Descendants("item")
select new
{
des = p.Element("description").Value
};
_xmlData = new List<string>();
foreach (var p in query)
{
_xmlData.Add(p.des.ToString());
}
MyTimer.Start();
}
private void MyTimer_tick(object sender, EventArgs e)
{
if (_xmlData.Count > 0)
{
string line = _xmlData[0];
_xmlData.RemoveAt(0);
tbs.Text = line;
}
}