2 Replies - 1028 Views - Last Post: 09 July 2016 - 12:17 PM

#1 Khatana  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 45
  • Joined: 07-December 13

Application level date change event handler in asp.net mvc

Posted 08 June 2016 - 01:38 AM

Hi, I want to call a C# method in a date change event handler of a datetime object in an asp.net mvc application (date time object or timer object is at server side), this datetime object is synchronized with system datetime object. Suppose mvc application is hosted and running in a server. When date changes at mid night, an event handler of date change must occurs and in that event handler I want to execute my C# code.
Please help me, how we can set a global date timer control, and how to set is event handler for date change.

Is This A Good Question/Topic? 0
  • +

Replies To: Application level date change event handler in asp.net mvc

#2 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Application level date change event handler in asp.net mvc

Posted 29 June 2016 - 04:42 PM

Feeling a bit necromantic so my take on what you're asking.

In a traditional web application based on HTTP whici is a series of requests and responses not going to happen. The reason is a traditional web app waits for a request, processes the result and spits out the response. In that flow the web server has no method of saying, "Hey, it's midnight. I want to do something now!" It has no understanding of time in that sense.

What you need is an external process that will trigger an action on an MVC controller. There are a wide variety of creating this process. It can be a simple console application the runs in the background and periodically checks the time to see if it is the target time. It could be a full blown .NET service with all kinds of bells and whistles associated with it that has multiple endpoints to handle different types of requests and respond to them. It could also be a NOdeJS server. Anything, as long as it runs continuously and checks to see if an action should take place.

Once the process needs to take the action it is simple to create a web request and send it to the server. If the process you create is in .NET you can create an HttpClient object and use that to forward a request to a URL that has been set up as a route in your MVC application.
Was This Post Helpful? 1
  • +
  • -

#3 Khatana  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 45
  • Joined: 07-December 13

Re: Application level date change event handler in asp.net mvc

Posted 09 July 2016 - 12:17 PM

Many thanks for your comprehensive and excellent reply. I'm convinced and happy. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1