【问题标题】:Asp.net: using Console application call Web-form application's methodAsp.net:使用控制台应用程序调用 Web 表单应用程序的方法
【发布时间】:2017-11-05 11:06:14
【问题描述】:

我正在尝试将 Web 表单 asp.net 应用程序转换为 Windows 服务。 我在控制台应用程序中有一个教程,用于转换 exe 文件,然后将其用作 Windows 服务。这是在 Windows 的启动中运行并继续。 我需要将 web 表单(使用 aspx、cs 文件)页面转换为将在 windows 启动时运行的服务。 或任何方式在使用计时器的情况下制作 web 表单页面的 cron-job,

aspx::
    <asp:Timer ID="Timer1" runat="server" Interval="" ontick="Timer1_Tick">
             </asp:Timer>
cs::
  public void CallMethod()//-------------------3
        {
            conCondition.GetConnectedConn();//con test from diff class
            CopyLocalDir();
            InsertAtmLogToDB();
            ParsedDataInsert();//
        }

        protected void Timer1_Tick(object sender, EventArgs e)//Ontick method-------defined in input----2
        {
            CallMethod();
        }

        public void getInterval()/// Called in page load-----to call::: Timer1_Tick-----------1
        {
            string selectTime = "select time from timer";
            con.Open();
            SqlCommand select = new SqlCommand(selectTime, con);
            SqlDataReader sdr = select.ExecuteReader();

            int setTime = 0;
            if (sdr.Read())
            {
                setTime = int.Parse(sdr["time"].ToString());
            }
            con.Close();
            Timer1.Interval = setTime;//set time to id(named Timer1) of input field(of aspx file)
        }

【问题讨论】:

  • 我投票决定将此问题作为离题结束,因为太宽泛不清楚service 是“始终开启”的,并由一些“监视”的事件触发。恕我直言,如果触发器是基于时间的事件,您最好通过Windows Scheduled Task 调用进程/exe

标签: c# asp.net timer webforms console-application


【解决方案1】:

将逻辑代码解耦成dll,从web表单和控制台引用dll会更好。

【讨论】:

    猜你喜欢
    • 2016-09-28
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多