how to continually check online file?
Messages   Related Types
This message was discovered on ASPFriends.com 'winforms-cs' list.


Edward Tanguay
I would like my WinForms application to read in an online XML file every 5
seconds in order to create a real-time chat client.

How can I fire the event without the user doing anything?

Thanks,
Edward Tanguay
http://www.tanguay.info

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Erik Brown
Edward,

Check out the Timer class in the Windows Forms namespace. The Tick
event for this class occurs at a regular interval whenever the timer is
enabled. Handle this event to process a recurring task such as the one
you described.

By the way, depending on your access to the server and the type of
chat you wish to build, there are some other implementation
alternatives. For example, a peer-to-peer TCP connection for a
one-on-one chat, or (more multi-person chat) a server-based chat
application that notifies registered clients when new information is
available (rather than client polling).

Good luck,

Erik Brown
----------
Author of "Windows Forms Programming with C#"
(www.manning.com/eebrown)

[Original message clipped]

Reply to this message...
 
    
John Corrigan
Look at the FileSystemWatcher class

-----Original Message-----
From: Edward Tanguay [mailto:Click here to reveal e-mail address]
Sent: Wednesday, May 15, 2002 8:33 AM
To: winforms-cs
Subject: [winforms-cs] how to continually check online file?

I would like my WinForms application to read in an online XML file every =
5=20
seconds in order to create a real-time chat client.

How can I fire the event without the user doing anything?

Thanks,
Edward Tanguay
http://www.tanguay.info

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail.=20
http://www.hotmail.com

| [winforms-cs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/winforms-cs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Edward Tanguay
I discovered Timer_Tick but it only fetches the website the first time
(although the label continues to be updated every 5 seconds in the following
code).

How can I get the Timer to fetch the web file on the second, third and
subsequent 5 second intervals as well (is there a cache somewhere I need to
turn off?)

private void Timer_Tick(object sender, System.EventArgs e)
{
object a = 0;
object b = 0;
object c = 0;
object d = 0;
BrowserMain.Navigate("http://localhost/cmxml/InfoAppHome.aspx";, ref a, ref
b, ref c, ref d);
TheTime.Text = DateTime.Now.ToString();
}

Thanks,
Edward Tanguay
http://www.tanguay.info

[Original message clipped]

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

Reply to this message...
 
    
Edward Tanguay
Hello Erik,

Thanks for the Timer class tip. I implemented it but the Timer only updates
my label but does not update the browser component.

Even the BrowserMain.Refresh() doesn't work.

I can however right click on the browser component and choose "Refresh" when
the program is running and it refreshes but for some reason will not refresh
programatically.

Any idea why the Timer can update my label but not the browser component?

private void timer1_Tick(object sender, System.EventArgs e)
{
object a = 0;
object b = 0;
object c = 0;
object d = 0;
BrowserMain.Navigate("http://localhost/cmxml/InfoAppHome.aspx";, ref a, ref
b, ref c, ref d);
BrowserMain.Refresh();
label1.Text = DateTime.Now.ToString();
}

Thanks,
Edward Tanguay
http://www.tanguay.info

[Original message clipped]

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

Reply to this message...
 
    
=?iso-8859-1?Q?Patrice_Calv=E9?=
I would suggest this alternative,

Have a Timer that ticks every second, or 1/2 second or....

At each Tick, check if there's a need to fetch an update. What you =
would normally do, is to have a "global" variable that handles the =
date/time of the last check, and another "global" variable that checks =
the interval. If the time now-lastcheck is > interval, run the =
download.

When you run the download, disable the timer at the beginning, download, =
do your stuff, set the lastcheck variable to now, re-enable the timer...

As your 1, 2 and 5 seconds is concerned, this would be done by the =
changing the interval.

Pat

Patrice Calv=E9
D=E9veloppeur S=E9nior - Senior Software Developer
Cactus Communications Internet
376 boul. St. Joseph
Hull, QC
J8Y3Y7
* Phone: 819.778.0313 * Fax: 819.420.0121
* E-mail:Click here to reveal e-mail address * Web:www.cactus.ca=20
"The gene pool needs a better lifeguard"

-----Original Message-----
From: Edward Tanguay [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, May 15, 2002 10:12
To: winforms-cs
Subject: [winforms-cs] Re: how to continually check online file?

I discovered Timer_Tick but it only fetches the website the first time=20
(although the label continues to be updated every 5 seconds in the =
following=20
code).

How can I get the Timer to fetch the web file on the second, third and=20
subsequent 5 second intervals as well (is there a cache somewhere I need =
to=20
turn off?)

private void Timer_Tick(object sender, System.EventArgs e)
{
object a =3D 0;
object b =3D 0;
object c =3D 0;
object d =3D 0;
BrowserMain.Navigate("http://localhost/cmxml/InfoAppHome.aspx";, ref a, =
ref=20
b, ref c, ref d);
TheTime.Text =3D DateTime.Now.ToString();
}

Thanks,
Edward Tanguay
http://www.tanguay.info

[Original message clipped]

_________________________________________________________________
Get your FREE download of MSN Explorer at =
http://explorer.msn.com/intl.asp.

| [winforms-cs] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/winforms-cs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Edward Tanguay
I discovered that even a Button Click will not reload or refresh the web
page in my WinForm. Perhaps there is some caching going on that I need to
stop?

Anyone know how to get the Explorer Browser component to programatically
refresh and reload new content from a web site as a Browser does?

Thanks,
Edward Tanguay
http://www.tanguay.info

private void ButtonRefresh_Click(object sender, System.EventArgs e)
{
object a = 0;
object b = 0;
object c = 0;
object d = 0;
BrowserMain.Navigate("http://localhost/cmxml/InfoAppPage1.aspx";, ref a,
ref b, ref c, ref d);
BrowserMain.Refresh();
}

[Original message clipped]

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

Reply to this message...
 
    
Erik Brown
Edward,

I thought you simply wanted to download a file at a regular interval.
Since you are displaying a page, why not use use the expiration policies
built into HTML. I'm not sure exactly how this works when displaying an
embedded window, but might be a better option here.

Check out the Cache property of the HttpResponse class for details.
See in particular the SetExpires() method, corresponding to the HTML
"expires" meta tag, that can set an expiration time for a page.

As to your below code, I would not repeatedly call Navigate(). Can
Navigate the first time, and the call Refresh() subsequently:

    private bool _firstTime = true;

    private void timer1_Tick(...)
    {
        . . .
        if (_firstTime)
        {
            myBrowser.Navigate(...);
        }
        else
        {
            myBrowser.Refresh();
        }
        . . .
    }

Hope this helps,

Erik Brown
----------
Author of "Windows Forms Programming with C#"
(www.manning.com/eebrown)

[Original message clipped]

Reply to this message...
 
 
System.DateTime
System.EventArgs
System.IO.FileSystemWatcher
System.Web.HttpResponse




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com