What to do while application waits for event - c#

I have written the basis for a reminder application using c#/wpf.
I am wanting to notify the user by a popup of some sort when a reminder is active.
I am not to sure how to go about when the application is doing nothing while it waits for the next reminder to be active.
Any ideas or help is appreciated
Edit*
What class's i would use

I think you're looking for a timer.
At your application startup and every time you add, change or delete a reminder, you look up the first existing reminder (in chronological order) and sets the timer to the time between now and the set reminder time.
When the timer callback is called you locate the correct reminder and act on it.

Related

Alternative to using asp:Timer for client updates

I have an asp.net web application that uses a timer to update all clients with new data. The data isn't in a database but is in a public static object shared by all clients. The timer has an OnTick method that updates each client's controls with this global data so all clients can view the most recent data. I'd like to update data fairly quickly, so I have the timer's interval set to 1 second.
The issue I've been seeing since implementing this timer is that sometimes button presses don't do anything. Sometimes (at random) the user has to click the button twice or more for anything to happen while other times a click works the first time. My guess is the button presses that have no effect happen because they were pressed at the same time the timer was executing the OnTick method (please correct me if I'm wrong). I set the timer interval to a much longer period and I didn't see these ineffectual button presses, so I know it has something to do with interference from the timer.
Is there an alternative to using timers and OnTick to update all client controls (without requiring each client to initiate or request the update)? Is there an event-driven way to update all clients rather than relying on a timer (i.e. all clients update on change in global data/on calling a certain method in the server code rather than at a set interval)?

Disable a button for t minutes

I want to disable a button for twenty minutes this should remain disabled even if the application is restarted.
I was thinking doing this by reading and storing the time when the button is pressed, then read the system time every minute and when the elapsed time be 20 or more minutes, enable the button.
I think this would allow me to restore the time when the button was pressed if the application is restarted; and then check for the elapsed time.
Do you think this is a good idea?
Any other option?
Since you want this setting to work even if the application restarts, this won't be possible unless you involve an external agent. A few options that you might try involve:
Read current Internet time from http://time.windows.com or nist etc and store it somewhere (registry or local file). Use a timer within your application that keeps fetching latest time from the Internet and compares it to the save value. This post allows you to read current Internet time using both HTTP and TCP port 13.
Use Windows scheduled tasks. Set a bool flag somewhere (file/registry again) and ask the scheduled task to clear the flag after 20 minutes. This post should get you going with creating scheduled tasks.
Create a Windows service that keeps running in the background that you could call to set the flag and the length of time for which this flag should remain set. The service should run an internal Timer (and should not rely on system time) to keep track of "ticks". After the specified time has elapsed, the service should clear he flag.
Here is what I am thinking,
When the application starts, disable or hide the button
Set the time stamp when disabling/hiding and store in a database table or a file.
Now read every minute or every five minutes - whichever is convenient to see if 20 minutes have elapsed.
IF 20 minutes have passed, remove the entry from table or file.
And if the application crashes or restarts before setting the time stamp:
1.While setting the time stamp, make sure that the table or file is empty. If not, enable the timer - the time stamp is there.
Well if I were you, I'd basically disable the button
and then start a timer, each minuite, the program should write the time left to a file as well as the current time ( you can also decrypt this file, so that users can't change it )
Now when the program restarts, it should read this file, and start a timer according to the written time in the fil :)
If you want the timer to work even when the program is closed, then you might check this out (File.GetLastAccessTime)
Basically, you should compare the (current time) that has been written to the fil, with the last access time, and make a function to get the time left :)
This might not be a perfect solution, but it will work fine ( I guess )
Kind Regards :)

How initiate an action at a particular time every day in c#.net

I am looking to do an action on every day at a particular time like triggers in sql, but here i am looking to do this in c#.net, can any one please help me,
Thanks
In general you are creating loop and then check if it's time for your action. It should be alwasy running process (service, or application in tray, etc).
It depends on how clear you need to be in your timer: if it needs to be second in second you need to create interval in 1 second and in Elapsed handler check you target time with current one, if true - fire alarm (event).

Solution to a timed out/End Date event

Hopefully someone can help me to look in the right direction for a solution to this issue I've come across during the design of a system.
I am creating an auction site in which the auction has a particular end date/time.
I have a .NET Timer displaying the remaining time to the user and when this countsdown it fires and event to update the back end SQL database to say the auction has completed and it informs the winning user and fires a CLOSE function.
How would you recommend doing this for auctions that aren't physically open in a browser at the time so the Timer event never creates this CLOSE event.
Ideally I need to run something at the point in time when an auction closing time has passed?
Thanks
One option is to store in the database the date/time that the auction item ends/closes. Then, don't worry about something reacting to it closing (timer in your case on the client) and updating it closed. What determines it's closed is simply the fact that now > closed date/time.
EDIT:
In the comment below you stated you also need to send mail when an auction closes. If that's the case, you need some sort of background processing to select all events that are closed and send mails. You can still define closed by storing a date time. That bg processing can select all events where now is greater than closed date and processed bit is false. Once you select those, put them in a durable queue (table in sql, azure queue etc...). Then have the background processing drain the queue. As it processes each item and sends mail, it updates the event as processed.
You have multiple options for background processing:
Windows Service
In proc timer with a threadpool to process (only do this if you have one AT)
Worker role in Azure
Sql Agent Job
Write a Windows service that polls the database at a set amount of time (I'd say a little less than the minimum length of an auction. For an example, say a day). That service would store in memory actions that will end within that amount of time, and check every second whether there are actions that ended. For auctions that have ended, fire your CLOSE event.

Show some message every day at 08:00 AM with ASP.NET C#

I want to read my database get values, change my old message with new value and then show this newly message. I want to do this reading job at everyday 08:00. How can I know if clock is 08:00 AM? Need to control every second? or what else?
The key thing to note here is that you don't actually need to do this at 8am - you need to do it when the application is in use at 8am or the first time the application is in use after 8am - if, that is, you want to do this solely within your ASP.NET application.
You need to track when the message was last updated.
In ASP.NET in a suitable application startup event, call the update method - which should check to see if the value needs updating - and then set a timer (its been 5 years since I wrote the code to do this last, options will have changed) for the "next" 8am - when the timer fires, call your update method, set the timer again. So, if the app starts it will update if required, if its running the update will happen.
If you have more access to the server then create a windows service to do the update.
There are several options in between these two - create a page or a web service to trigger the update logic within the ASP.NET application and then use an external timer to open the page/call the web service at the scheduled time. The most appropriate solution depends on your hosting enviroment and the other resources available to you.
you could create a windows service and schedule it for the time you require every day.

Categories

Resources