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.
Related
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 :)
i am working on an asp.net web application, where tasks are assigned to users, we set standard time to every task, in that standard time period the user has to finish the task, there are two buttons on the page, proceed and save, when a user clicks on proceed button, the time is saved in database as starttime, and when the user clicks on save button, the time is saved in database as endtime. this way we are capturing the time period within which the user is completing the task.
the standard time is set on an average time study basis, not every time the task takes the same amount of time.
often users can complete the task in very less time than the standard time, in this case the users are proceeding the task and even after completing the task, instead of saving it, they lock the system and go for tea breaks and after coming from break, they save the task.
i want to save some information on the web page when they lock the pc even when the browser is minimized.
i tried implementing applet using jintellitype library but its not capturing the key combinations that are used by windows os.
i also tried using Silverlight but there is no such support as in winforms application in Silverlight, i have to create a com component or something that interacts with system32 or some native api. it doesn't seem easy for me, i would like to know if there is such library for Silverlight.
it should be browser independent, i haven't tried ActiveX, but i think it can be done using ActiveX, but i don't want to use ActiveX as it runs only on IE.
i want to know all the possible solutions to achieve this.
thanks in advance.
Why don´t you set a kind of timer-check to know if the last time is too far from the correspondent (and previewed) time to perform the job? If a task may expend, for instance, from 1 to 5 minutes, have 21 minutes is too far.
Why din´t you create a timer to TIMEOUT user? If users know they will be timed-out after some time, probably, they won´t leave to coffre-break during the test (a kind of penalty must be aggregated on this, like start from the initial point if timeout).
Why don´t you automatically save the record after the job finish, instead obly the user to press a button?
Until I know, you can perform SUSPEND mode, but not detect them if started from other apps.
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.
I have a win-form application developed in .net 4.0 and using SQL 2008 as DBMS.
User can open an item from a list of item and every time they open, I am updating the database with the userId to state the particular item is opened by particular user so other users can’t open the same item at same time. Also when user closes the item I am resetting it back to normal where others can open.
But I am wondering how to update the database if some ones system got crashed/stuck or something similar. Is there any good solution to handle these kinds of situations?
One solution would be to add a time stamp column into the data table. Every time a user accesses an item (in addition to other work) you set this time stamp value.
You can then have a separate task/service that iterates thought the records and releases any expired locks once in a while.
So you're trying to implement your own locking mechanism. See how to mitigate the problems of Deadlocking that should give you an idea. Basically either you use notifications or stamps to track lock's owner status (if it's dead or still using the resource), preventing resource starvation.
Requested example
There are 2 users. User A and User B.
User A open a view within your app, then two things happen:
You update the DB and set the stamp to the current time.
You start a new background thread who will be responsible to mantain the lock. This background thread must wait N-Delta where N is the maximum minutes the resource can be locked without renew and delta is the delta for update time. So, for example, suppose a view can be locked for maximum 15 minutes without user activity, then your thread must wait 15-1 (taking that will probably take 1 minute to notify DB "better be caution with this time").
Then User B try to access to that view, you check on the db for the resource and for the lock table and if there's a lock on that view whose time isn't superior from 15 minutes then you deny access. BUT if time is most that 15 minutes you grant the access to the User B and remove the access from the User A.
If either User A or User B successfully close the view, then you just remove the entrance from the DB.
This is a very simple example but should give you an idea of what I mean.
I have faced similar situation before. In such cases you will have to assume how much maximum time would a user take to action on that item (say 15 mins). Create a table called item_lock with 2 columns: item_id, lock_aquired_time. Every time a user clicks on any item, a record would get inserted into this table. If any other user tries to open that item.. a notification would pop up on his screen that the resource is locked for actioning by XYZ. Futher you will need to create a service which would run say every minute and will remove any record which is older than 15 mins.
PS: Whenever any user has finished taking action on any item.. that row would get deleted from item_lock table.
I want to create something like a client in c#.
But I do not know that how I can learn computer status like sleep mode, off, logged in or logged out.
Also, I need to get the warning if the user haven't used the computer for 10 minutes.
You can find information about currently logged user and how to hook the Locked/Unlocked events in this thread.
There are some other different approaches you might try:
You can use the System.Diagnostics and get the process list via Processes.GetProcesses(). Just keep an eye on the Idle process -- if it runs for more than 50% CPU longer than 10 mins the user seems to be idling too.
You can use Performance Counters to monitor the activity taking place on the computer and make certain decisions.
You can also use the WMI service with similar purposes.
Partial answer:
User activity/inactivity can be monitored using hooks. Start a timer with a 10-minute interval. Whenever you detect a keyboard/mouse message, restart it. If the timer event happens, than you detected 10 minutes of inactivity.