Hello,

I have a web app that on a buttonClick event it goes and checks a database for a particular field. if that field = a certain value, the app does something.

is there a way to make this app run every x seconds rather than on a buttonClick? do i need a timer? make the whole app run as a service?

if you can provide an example, that would be much appreciated.

thank you in advance

Recommended Answers

All 8 Replies

Hello,

I have a web app that on a buttonClick event it goes and checks a database for a particular field. if that field = a certain value, the app does something.

is there a way to make this app run every x seconds rather than on a buttonClick? do i need a timer? make the whole app run as a service?

if you can provide an example, that would be much appreciated.

thank you in advance

It would probably be easier with a timer. Just create a timer, then on the button click, it will enable it and call it at a given interval.

private void button1_Click(object sender, EventArgs e)
        {
            timer1.Interval = 25000;    // 25 seconds
            timer1.Enabled = true;
            timer1.Tick += new EventHandler(function you want  reloaded);
        }

Hope this helps.

sfrider0, thanks for your reply... but is there a way not to use the button click, what if the server rebooted, do i need to hit the button to kick off the timer? if yes, i don't think that is a good idea, i need it to keep running all the time.

thank you again.

You could place the code of sfrider0 after InitialiseComponent in the contructor of your form, or in the form load event handler.
Your timer Tick event handler should check for errors etc. and act as you wish. Succes!

ddanbe,
thanks for your reply, can you please provide an example?
just to be clear, i need this app to run all the time without any user intervention.
thanks in advance.

ddanbe,

also, this code doesn't have any interface... if you know VB6, you could write a code to do something and package the code to be an .exe file, then to execute it, you either double click on it or create a task schedule to execute it every x seconds.

thanks

This is how you could setup things, after you dragged a Timer control from the toolbox on your form:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           //see sfrider
            timer1.Interval = 25000;    // 25 seconds            
            timer1.Enabled = true;            
            timer1.Tick += new EventHandler(TimeWatcher);
        }

        private void TimeWatcher(object sender, EventArgs e)
        {
            //The running program will come here at every timer1 interval
            //Do the things you want to do 
        }
    }

With your last post you are telling other things, do you mean something like an AT command? For the meanwhile you could call the Hide method, so your app is not visible.

>>is there a way to make this app run every x seconds rather than on a buttonClick? do i need a timer? make the whole app run as a service?

If you want the application to run without user intervention I would suggest using a service. What are you trying to do exactly, and what is the interval going to be on your timer? You want to be careful not to hammer the SQL server.

>>also, this code doesn't have any interface... if you know VB6, you could write a code to do something and package the code to be an .exe file, then to execute it, you either double click on it or create a task schedule to execute it every x seconds.

This approach is problematic. With every newer version of windows the task scheduler works less like it once did.

you can write a very little javascript to fire the button's click event without doing anything else. there is a settimeout function in javascript. you will use document.getelementbyId("buttonClientID").click() within your javascript function. if i were you i would post this question to asp.net forum. unfortunately i am too busy to provide code now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.