473,507 Members | 11,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timer+xml

I am writing a program to get the content of a xml file at a interval time.
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer mainxmltmr = new System.Timers.Timer(10000);
mainxmltmr.Elapsed += new
System.Timers.ElapsedEventHandler(mainxmltmr_Elaps ed);
mainxmltmr.Start();
}

private void mainxmltmr_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
try
{
string strXmlFile = "http://localhost/xml.xml";
XmlDocument objXml = new XmlDocument();
objXml.Load(strXmlFile);
XmlElement objDocumentRoot = objXml.DocumentElement;

label1.Text = objDocumentRoot.GetAttribute("value");
}
catch (Exception){}
}

}
}
<?xml version="1.0" encoding="UTF-8" ?>
<AF value="hi">
</AF>
Jun 27 '08 #1
6 1357
"Elliot" <el************@hotmail.co.ukwrote:
I am writing a program to get the content of a xml file at a interval
time.
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.
[...]
catch (Exception){}
Handle the exception, then.

Eq.
Jun 27 '08 #2
label1.Text is still the default one "label1".
"Elliot" <el************@hotmail.co.ukwrote in message
news:4C**********************************@microsof t.com...
I am writing a program to get the content of a xml file at a interval
time. However, label1.Text did not change. Can anyone find the problem for
me?
Any idea would be appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer mainxmltmr = new
System.Timers.Timer(10000);
mainxmltmr.Elapsed += new
System.Timers.ElapsedEventHandler(mainxmltmr_Elaps ed);
mainxmltmr.Start();
}

private void mainxmltmr_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
try
{
string strXmlFile = "http://localhost/xml.xml";
XmlDocument objXml = new XmlDocument();
objXml.Load(strXmlFile);
XmlElement objDocumentRoot = objXml.DocumentElement;

label1.Text = objDocumentRoot.GetAttribute("value");
}
catch (Exception){}
}

}
}
<?xml version="1.0" encoding="UTF-8" ?>
<AF value="hi">
</AF>

Jun 27 '08 #3
On Jun 22, 5:29*pm, "Elliot" <elliot_barc...@hotmail.co.ukwrote:
I am writing a program to get the content of a xml file at a interval time..
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApplication1
{
* * public partial class Form1 : Form
* * {
* * * * public Form1()
* * * * {
* * * * * * InitializeComponent();
* * * * }

* * * * private void Form1_Load(object sender, EventArgs e)
* * * * {
* * * * * * System.Timers.Timer mainxmltmr = new System.Timers.Timer(10000);
* * * * * * mainxmltmr.Elapsed += new
System.Timers.ElapsedEventHandler(mainxmltmr_Elaps ed);
* * * * * * mainxmltmr.Start();
* * * * }

* * * * private void mainxmltmr_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
* * * * {
* * * * * * try
* * * * * * {
* * * * * * * * string strXmlFile = "http://localhost/xml.xml";
* * * * * * * * XmlDocument objXml = new XmlDocument();
* * * * * * * * objXml.Load(strXmlFile);
* * * * * * * * XmlElement objDocumentRoot = objXml.DocumentElement;

* * * * * * * * label1.Text = objDocumentRoot.GetAttribute("value");
* * * * * * }
* * * * * * catch (Exception){}
* * * * }

* * }

}

<?xml version="1.0" encoding="UTF-8" ?>
<AF value="hi">
</AF>
The obvious idea is that XmlDocument.Load throws an exception; what
really hints at it is that you have encased it into try-catch for
whatever reason. How about removing that catch, and seeing if it
throws anything (and if so, what is it)?
Jun 27 '08 #4
I tried another method and no problem found.
Thanks for your idea.
"Paul E Collins" <fi******************@CL4.orgwrote in message
news:zK******************************@bt.com...
"Elliot" <el************@hotmail.co.ukwrote:
>I am writing a program to get the content of a xml file at a interval
time.
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.
[...]
catch (Exception){}

Handle the exception, then.

Eq.

Jun 27 '08 #5
On Sun, 22 Jun 2008 09:32:12 -0700, Pavel Minaev <in****@gmail.comwrote:
The obvious idea is that XmlDocument.Load throws an exception; what
really hints at it is that you have encased it into try-catch for
whatever reason. How about removing that catch, and seeing if it
throws anything (and if so, what is it)?
The exception is almost certainly the Control class's cross-thread
exception, seeing as he's trying to set the Text property from within the
event handler for a System.Timers.Timer object.

To the OP: you either need to switch to the System.Windows.Forms.Timer
class or use Control.Invoke() to assign the Text property.

Pete
Jun 27 '08 #6
Great! I will try it. Thanks.

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 22 Jun 2008 09:32:12 -0700, Pavel Minaev <in****@gmail.comwrote:
>The obvious idea is that XmlDocument.Load throws an exception; what
really hints at it is that you have encased it into try-catch for
whatever reason. How about removing that catch, and seeing if it
throws anything (and if so, what is it)?

The exception is almost certainly the Control class's cross-thread
exception, seeing as he's trying to set the Text property from within the
event handler for a System.Timers.Timer object.

To the OP: you either need to switch to the System.Windows.Forms.Timer
class or use Control.Invoke() to assign the Text property.

Pete
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2498
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
3
3275
by: Chris Hayes | last post by:
I'm trying to create a nifty Windows Service that will perform tasks at a predetermined interval. To make sure I understand the timing correctly I have set an emailer utility to email me on the...
2
8948
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
11
7521
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
4
1674
by: Daniel | last post by:
Hey guys Here is what i want to do. I have made a multiplayer game that needs to when more than one player is ready start a countdown that the clients can see, so players can still join in this...
6
5588
by: venmore | last post by:
Hi Can someone please point in the right direction. I have an XML file that gets updated every 4 hours on a web server. I can check the XML modification time in ASP and compare to the databse....
4
2843
by: Manikandan | last post by:
Hi, I'm working with XML serialization. I'm writing a xml file of huge size(above 500MB) I need to show the user the progress of writing to file using progress bar. For this i need to create a...
2
1196
by: dev121 | last post by:
Hi all, I have attempted to create a vb.net application that can extract neccessary data from a xml file to txt format. This is all working fine. The next step for me is to be able to scan a...
4
4513
by: agun | last post by:
Hello, Hi, i'm really a newbie in programming, especially javascript. I have one question in my mind right now. Sorry before if i'm not clear. Please see this example: ...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.