Hello friends !!!!!
I want to do a project similar to alarm clock.
If I have written some timings in a string or some thing, whne the current time of clock equals to the timings given it should display the next time given in that string to the user in form of alarm or it should display the form with that time on screen even if the user is using other applications...
Hope my concept is clear to you all .Please Help me in this
Thanks in advance.
:icon_cry:

Dani AI

Generated

— clarify whether this is a desktop app or an ASP.NET/web page. A server cannot pop a desktop window on a client; web scenarios need client-side code (setInterval/notifications) or SignalR. ’s timer idea is on the right track, but rather than polling every minute, compute the next alarm time and set a single-shot timer. ’s pill project is a useful example of the end behavior.

A compact desktop workflow (WinForms/VB.NET):

  • Parse the timings string into a list of TimeSpan values.
  • Convert those to DateTime instances for "today" (roll to tomorrow if already past).
  • Pick the nearest future DateTime, compute the due milliseconds, and start a one-shot timer.
  • When the timer fires, show/raise the alarm form, play sound, then compute/schedule the next alarm.

Example VB.NET skeleton:

Function ParseTimes(s As String) As List(Of TimeSpan)
    Return s.Split(","c).Select(Function(t) TimeSpan.Parse(t.Trim())).ToList()
End Function

Function NextAlarm(times As List(Of TimeSpan)) As DateTime
    Dim now = DateTime.Now
    Dim candidates = times.Select(Function(ts) New DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0))
    Dim next = candidates.Where(Function(d) d > now).OrderBy(Function(d) d).FirstOrDefault()
    If next = DateTime.MinValue Then next = candidates.OrderBy(Function(d) d).First().AddDays(1)
    Return next
End Function

To bring a form to the front: set TopMost = True, restore if minimized, call BringToFront()/Activate(). Windows focus rules can prevent stealing focus; use SetForegroundWindow (P/Invoke) or FlashWindowEx as a fallback. See Microsoft docs for details: SetForegroundWindow and FlashWindowEx.

Caveats: keep persisted alarm data (config/file), handle daylight savings/time zones (DateTimeOffset if needed), and note timer interval limits (use intermediate timers if the due interval exceeds Int32.MaxValue). If the app must work when not running, schedule a Windows Task (see Task Scheduler docs) rather than relying on an in-memory timer.

Recommended Answers

All 2 Replies

I'd put a timer in the app to check the system time every minute or so. If the value is greater than your string value, have do whatever you want. Also, have a flag of 0 or 1 to make sure it hasn't already gone off.

Here is a project I use to let me know when I have to take pills.
Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.