Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

Asp.net - need to run a method every 5 minutes

I have a web site and I need to run a method every 5 minutes...any way to do this without an infinite loop or sleep method...I know of windows services but I'm a little new to that...I'm using vb.net....
Avatar of roshnipatel
roshnipatel

You may want to write a simple console app that calls the function once in your main().  Then Schedule the exe to run every 5 min from the Window's Scheduler.

Setting it up as a service is also a good way to handle it.  
Here's an article that helps with that:
http://support.microsoft.com/kb/317421
Avatar of GlobaLevel

ASKER

great idea...however if its a console app...I need to pass values from my website to the .exe and the results from the .exe back to the website...I should have mentioned that b4...
This isn't the best suggestion I've given, but without knowing why you need this, maybe you should write the values from your site to a text file (or db) and then use the console app to read the values and run the function.

If you can share a little more about what you are doing and why, I'm sure we can come up with a better soln.
Avatar of Deja Anbu
I don't know about the requirment.. but a simple thought..in timer also, you can achieve this.

 <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="300000"></asp:Timer>

but not sure whether this is a good idea for u..

ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops.  Correction on my previous post.  What I meant with "You need to drag an Ajax Extension ScriptManager and Manager to this." was

You need to drag an Ajax Extension ScriptManager and Timer.
Some great suggestions...the goal is to ping a bunch of ip addresses and domain names at different time intervals and return the results back to the site for reporting needs....
Well, the use of a background thread would in a way address your situation.  However, be aware that there are limits to the number of threads you can use depending on memory and so on.  Also, you might want to have a look at ThreadPool for multithreading.

http://msdn.microsoft.com/en-us/library/0ka9477y.aspx
Also this has to run 24/7/365...so that's a factor as well
OK.  Why don't you just run a standalone multithreading Windows Application then if 24/7/365.  At least you have more control to it than Windows Service.  Also, a web site is really not suitable if this is the case.  

You can still use multiple background threads with multiple timers if you want in an application.  Or, you could create instances of the Windows application where you could for instance select your target URL in a dropdownlist and each application runs a background thread independent on the other background thread.   There are pros and cons to this.  It will be bit harder to maintain if everything is done in one application but it will be cleaner.  With different instances, logic would be cleaner in each app but it would be hard managing all of those applications if you have say 15 apps running at the same time.   However, you are assured that each thread is really independent of each other and the chance of crashing the app would be less than stacking them all in one instance.

OK.  Why don't you just run a standalone multithreading Windows Application then if 24/7/365.  At least you have more control to it than Windows Service.  Also, a web site is really not suitable if this is the case.  

>> fine with me..im a little weak on the multi threading...but i will review your link above...
I reviewed the article you posted..a few questions if I may:

thread to block for long periods of time
>>Does this mean that the background worker thread is idle for some time('Block')

single-threaded apartment.
>> is a collection of threads whether foreground or background that have similar properties...

Threadpool
>> is a collection threads all in 'queue' to be processed...
also in the threadpool examples....
Executing Asynchronous Tasks with the Task Parallel Library
Executing Code Asynchronously with QueueUserWorkItem
Supplying Task Data for QueueUserWorkItem
Using RegisterWaitForSingleObject

...which would I use if I have 5 processes:

process1: run every 5 minutes
process2: run every 10 minutes
process3: run every 30 minutes
process4: run every 60 minutes
process5: once a day




I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Apologies for the delay need to accept this comment:
35744266Author:Alfred1Date:05/12/11 02:01 AMExpert Comment