I just created a simple clock alarm using datepicker by 'dynDateTime' on ASP.net. the alarm is working well, however, I want the alarm to be still running even though I have closed the browser. Is there any way to achieve this/ any idea on what kind of integration needed?
Here is the running code for the alarm clock
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Media;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows;
public partial class Default : System.Web.UI.Page
{
System.Timers.Timer timer;
private DateTime dob;
protected void Page_Load(object sender, EventArgs e)
{
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += Timer_Elapsed;
}
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
DateTime currentTime = DateTime.Now;
if (currentTime.Year == dob.Year && currentTime.Month == dob.Month && currentTime.Day == dob.Day && currentTime.Hour == dob.Hour && currentTime.Minute == dob.Minute && currentTime.Second == dob.Second)
{
timer.Stop();
try
{
SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Users\mfahmi\Desktop\alarm.wav";
player.PlayLooping();
}
catch (Exception ex)
{
Label2.Text = ex.Message;
Label2.Visible = true;
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
dob = DateTime.Parse(Request.Form[TextBox1.UniqueID]);
Label1.Text = dob.ToString();
timer.Start();
}
}
and below is the code for design page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.dynDateTime.min.js" type="text/javascript"></script>
<script src="Scripts/calendar-en.min.js" type="text/javascript"></script>
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#<%=TextBox1.ClientID %>").dynDateTime({
showsTime: true,
ifFormat: "%Y/%m/%d %H:%M",
daFormat: "%l;%M %p, %e %m, %Y",
align: "BR",
electric: false,
singleClick: false,
displayArea: ".siblings('.dtcDisplayArea')",
button: ".next()"
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" ReadOnly = "true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<img src="calender.png" />
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
*the thing is, i'm trying to build a scheduler for my asp.net web application where user set a schedule to run a task on the datepicker.