I have an ASP.NET MVC4 website running and now i need some sort of background task that is continously running. But is this even possible?
The MVC4 website is a sort of notifying system. Other websites can register a Callback URL on this website and this website should trigger that callback URL for a specified interval. So, for every hour for example.
Normally the code of my website only becomes active when I visit a page. But in order to make this work I need a way to have my ASP.NET website to run in the background continously. So it can do its checks and make an HTTP call when necessary.
It's important though that other websites can register their own Callback url through an http web request, and not through a socket.
Is something like this possible in an ASP.NET MVC web application? Or do I need a different approach?
Check this out: Easy Background Tasks in ASP.NET MVC
I do not prefer to run continuous jobs in asp.net because of these reasons.
You can use Windows Azure Scheduler for scheduling http requests for a particular URL.
Alternatively you can create a Windows service (example here)
You can also try console app and schedule it using Windows task schedule
Azure Worker Role is also a good option
Related
I'm going to develop an application which is in charge of running tasks which may take several days.
I want to develop a web application as UI for it.
This web application is in charge of starting/stopping/pausing tasks and also it should report the progress of task whenever I login back to the application.
I already developed many desktop / ASP.NET MVC web applications however I have no idea which .NET component or technology should be used for developing such application.
I guess my application should be composed of two main components:
The part which is running long-running tasks (may something like a service and I don't know how services are implemented in C#).
A web-UI which binds to this services and control/monitor its activity.
I would be grateful if you can suggest the components which can manage this requirement.
I have a saas web application using asp web api hosted in azure. I need to schedule some tasks to:
Generate monthly/yearly billing
Run recurring sql script
Send daily summary to users by email
Any recommendation or pointer on how i can do this? Should i create another app or can i host it inside my web api app?
If you want to have a reliable tasks scheduling wherein you can apply time interval depend on your choice, I recommend Quartz. Quartz allow to add/edit/delete/etc a scheduled task easily, manageable and no CPU overhead.
This is what Azure Web Jobs are for - running background tasks. It is a feature of the Azure Web App your Web API is running in. You can set it up as a scheduled job using the Azure Scheduler. How to do this is also in the link I provided.
I have a job I'd like to run on my new Azure hosted web app. In the old pre-Azure days, I would create an .aspx page that did the job, then have some service that simply called the url (www.mysite.com/folder/myjob.aspx) on a schedule.
Is there a better way to do this with webjobs? Can I interact with the actual object model of my site or am I restricted to public URLs and the such?
I've heard I can write a full application (.exe) and host that, but I'm wondering what the advantage of that is?
There are a couple of ways to do this
Azure Worker Roles -Create a console application and then spin this cloud service executes the console app or process. https://azure.microsoft.com/en-us/documentation/articles/fundamentals-introduction-to-azure/
Azure Website Jobs - https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/
I think website jobs is what you really are looking for. Build a little powershell or EXE of what you want doing then set it on a website job with a schedule. I don't think there is really much advantage either way, if you are already in the azure cloud this is just another service to leverage. We currently use both jobs and worker roles. Worker roles have the advantage of scaling out if needed.
I am working on a ASP.NET MVC project that should be implement a multi-threading functionality. In fact, in this application, a user can navigate from a page to an other, so he can change the action of his current controller. My question is, Is there a way in ASP.NET MVC that can guarantee that the action is running in background, even though the user has switched the action. It means that even when he returns to the View after he navigates, he can get what he has launched in his current session (knowing that it may take a bit of time in order to do it).I know that it is contradictory with the MVC pattern, but this application should be a server side application.
I did some research and they say that a thread pool and asychronous controllers (http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx#performing_multiple_operations_in_parallel) may be a solution to this problem. I will be glad to hear any other suggestions to help me implement this project in the right way.
I think you should re-visit the premise that this should be implementing a parallel pattern.
For this to work the way I think you want it to, you will need a shared cache keyed by session id's. Your asynchronous tasks will be storing their results there. You will need some middleware that is initialized when the app initializes, this middleware would consist of a managed thread pool and a buffered queue of tasks. Your UI threads/web server threads would queue a task for the middleware to handle and dump the results in the shared cache which you would then check for results on subsequent web requests from that client. That's a lot of work. Especially if your client and server side applications are already intimately tied together as they usually are in ASP.NET.
Or, you could move the application away from ASP.NET and implement the server side application as a REST API in C# that your client application, written in Javascript, would hit using ajax requests. You build the client app as a single page app in some js MVC framework. This will allow the user to the client app in a seamless experience as calls to the server are non-blocking unless the client app wants them to be. Then there's really no need for the asynchronous patterns you mentioned above, which, honestly are not going to give you any sort of performance gains and it's not going to scale well.
I would like to set timer for getting page source from some page and compare it if some changes happens with a version of yesterday.
which logic should i use to call some page once a day? my program is just a webpage and it cant send requests every 24 hours. how can i achieve to send request and check if changes happens?
you don't want to use a Web Application to do this, since a Web application typically responds to requests and doesn't wake up and make requests of its own (which is what you need).
What you need is a regular .NET application. It could be a console application that makes the call out to this other website. you could use the WebClient class or similar to do the job.
Once you have it all working, you can use Windows Scheduler to schedule the task at whatever interval you need.
If you need to then communicate with you Web Application from the console app, you can do the same thing, that is make a request to a specific page or handler from you console app (just like you called a page on the other website). When you web application receives the request, you can act on this and do what you need to.
Keep in mind that if all you need to do is update some database tables, you might as well do that from the console application.
Think of your console app (that uses WebClient) as a custom browser. You can call any url you need to and the Web application on the other end sees that call as if it were made by a browser. So using you specialized "browser" you can call other web sites as well as your own.