【发布时间】: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