Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have an aspx page which does not have any design. Only some code on code behind file. I need to run this page on every 5 minutes from server. This page also need not display on any browser. Is there any option available for me to run this page repeatedly on a regular basis. No browser will display and also it should happen in server(IIS).


I can not go with exe(Windows Application).
Posted
Updated 7-Oct-14 0:52am
v2
Comments
Kornfeld Eliyahu Peter 7-Oct-14 6:28am    
It is completely wrong! Why web page if no browser and no UI. Why IIS if you have repeating task?
Web sites (and IIS host web sites!) are used to response to user request - that's the way web sites are build!
It seems you got your solution all wrong...
You may present your problem and your solution in grater details so someone may help you better...
Sunil Kumar Pandab 7-Oct-14 6:49am    
I need to run some c# code in regular interval and that will be hosted in server only. Kindly tell me any open suggestion. I can not go for exe file or some batch file. I have resources as IIS, asp.net website project.
Dave Kreskowiak 7-Oct-14 9:57am    
You really do NOT have an option here. The only way to get it to go is to fire off a web request to load that page, every 5 minutes. That alone will take a seperate .EXE!!


Scott Hanselman documented the available options for running background tasks in ASP.NET applications:
http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx[^]

If you're using .NET 4.5.2, you can use the new QueueBackgroundWorkItem API[^].

Scott's recommendation seems to be to use Hangfire[^], but he lists several other options as well.
 
Share this answer
 
Write this code in Global.ascx page
C#
void Application_Start(object sender, EventArgs e)
        {
            try
            {
                new Task(() =>
                {
                    while (true)
                    {
                        WebClient web = new WebClient();
                        web.DownloadData("http://localhost:60749/Default.aspx");
                        System.Threading.Thread.Sleep(300000);
                    }

                }).Start();
            }
            catch (Exception ex)
            {
            }
        }


give the Url of the page which you want to execute the page in Time intervels.
this page will execute every 5 mints intervel
 
Share this answer
 
Comments
Sunil Kumar Pandab 8-Oct-14 8:52am    
I tried this solutions and its working fine. I write code in global.asax and got the result as required. thanks for your solution.
If you want anything like that then use Windows Service which can be configured as per your timings and would invoke methods in OnStart(), rather then using any aspx page. you can create an .exe of it and run it once and would call the methods as per your requirements

Refer this link for development : Windows service tutorial
 
Share this answer
 
Comments
Sunil Kumar Pandab 7-Oct-14 6:46am    
I do not have to go for exe. I have only option to do with a web page which has some code in code behind and need to run in every 5 minutes. Is there any option to do with IIS and asp.net website project.
Thanks7872 7-Oct-14 7:42am    
But why If you have nothing to do with browser?
Write that code behind code in Windows application (we do with windows service also)
if you build that windows application you will get exe file. using that exe file
create task scheduler

To create task scheduler please refer this link

http://windows.microsoft.com/en-in/windows/schedule-task#1TC=windows-7[^]

I think this is better solution
 
Share this answer
 
v2
Comments
Sunil Kumar Pandab 7-Oct-14 6:52am    
No i can not go with exe. I have only option to do with web project.
Samatha Reddy G 7-Oct-14 7:41am    
sorry i dont konw about web project, i will try if i will get the solution i will inform to you
KaushalJB 7-Oct-14 9:46am    
oh my gosh !! web project....
You can add
Meta refresh tag to your page[^]

And on Page_Load do whatever you have to do.

The major problem is that the page HAS TO BE OPENED IN THE BROWSER. So, either you have the page on the server opened constantly or you have to open it somewhere.


Alternatively, you could create windows service ON YOUR OWN COMPUTER or any other that you DO have access to, that would call your page every 5 minutes via WebRequest. But then that computer should be online 24/7.


Using web only is senseless requirement. The technology is not built for this and you should really describe your problem in more details and let us help you.

WHY are your options so limited? What do you have to do?

If this is something for your site which you're hosting and have no access to anything but web technology...how about database? There are scheduled tasks that you can program to do whatever. Today database servers are capable of running .NET code, send e-mails and gazillion other things.
 
Share this answer
 
v3
Comments
Thanks7872 7-Oct-14 7:40am    
Requirement is not at all senseless. There is nothing wrong in performing some task every x mins. Solution doesn't suit here.
Sinisa Hajnal 7-Oct-14 7:54am    
I meant the requirement to use only IIS and web page(s)
Thanks7872 7-Oct-14 7:57am    
Why web page?
Sinisa Hajnal 7-Oct-14 7:58am    
Because that is what Sunil asks for. That is his limitation. Now please remove that 1-vote from my solution! It is the only one taking into consideration what he asked for.
Thanks7872 7-Oct-14 8:09am    
First of all, vote can't be removed. Further, i would have voted up if you suggested OP the right way. e.g. See the comment by Kornfeld above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900