Web Application - Scheduled Tasks Tip

Back to Blog Listing

When writing web applications, its common to want to have some code run at scheduled times – e.g. to synchronise an update. As the main body of the code is in a web application, and there is no distributed code, the easiest place to implement the code is inside the web application, perhaps with a web service or a simple web page as the interface.

Windows comes with a tool that allows programs to be scheduled to run as desired – Task Scheduler. The Task Scheduler can be used to call the web page. Often, developers start Internet Explorer from Task Scheduler and ask it to visit the web page URL. However, this can be problematic – sometimes IExplore.exe does not shut down and after a few Tasks IExplore never actually visits the web page, despite the Task history showing as the task executed correctly.

As the full functionality of a browser is not required, there are other techniques that can be used. One that we have found works well is to use Task Scheduler to start powershell.

Task Scheduler

This is as simple as using IExplore.exe, instead start powershell.

An example of the call with parameters:

powershell -ExecutionPolicy unrestricted -Command "(New-Object Net.WebClient).DownloadString(\"\")"

This is more lightweight than Internet Explorer and has proven to be reliable.



14 Aug 2014

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.


C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner