How to make code execute automatically every minute in asp.net mvc5 my websites

I have this code I have done using the application console and I want to use it inside my website using asp.net mvc5 in order to store the data it brings from the RSS feeds and store it in a database

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using CodeHollow.FeedReader;
using CodeHollow.FeedReader.Feeds;
using System.Data;
using System.Data.SqlClient;
using System.Data.Entity.Core;
using System.Data.Entity.Infrastructure;

namespace RssFeedBackEnd
{


public class Program
{
    public static void Main(string[] args)
    {


        RssFeedDB db = new RssFeedDB();

        var qry = (from c in db.Links select c);

        foreach (var li in qry)
        {
            try
            {

                var feed = FeedReader.Read(li.adressLink);

                var item = feed.Items;


                if (feed.Type.ToString() == "Rss_2_0")
                {


                    //New n = new New();
                    foreach (var items in item)
                    {
                        string v = items.Id;
                        int h = validate(v);

                        if (h == 0)
                        {
                            try
                            {

                                New n = new New();

                                n.TitleNews = items.Title;
                                n.LinkNews = items.Link;
                                n.TitlePage = feed.Title;
                                n.LinkPage = feed.Link;
                                n.Linkimg = items.SpecificItem.Element.Element("enclosure").Attribute("url").Value;
                                n.IDurl = items.Id;
                                n.Pubdate = DateTime.Now;
                                n.EntryTime = DateTime.Now;
                                n.Description = items.Description;
                                n.IdCatogrey = li.CategorayID;
                                //n.NameCatogrey = li.Category.NameCategory.ToString();
                                db.News.Add(n);

                            }
                            catch { }

                        }
                    }

                }

            }

            catch { } 
        }
        db.SaveChanges();


    }


      static int  validate(string n) {

        int a = 0;

        RssFeedDB db = new RssFeedDB();


        var qry = (from m in db.News select m);

        foreach (var nws in qry)
        {
            if (nws.IDurl == n) { a =1; break; }
        }

        return a;

    }         
 }}

I hope to help me how to put it inside the web application and do his work every minute .

The idea of ​​my project is to fetch data (news) from RSS feeds links and store them in the database to display on my website.

I hope I’ve shown you very well what I want to do.

Leave a Reply

Your email address will not be published. Required fields are marked *