Popup window / message for remaining time - vb.net

I have several froms in my application. When application starts, a timer starts for 30 minutes.
I want to show the remaining time using a popup window, message or whatever, on whichever form the user is at that time.
Please advise how to do it.
Thanks
Furqan

The timer objects in the .net framework do not give access to the time already elapsed or remaining.
However when your application starts you will can create and start a stop watch.
private _sw as System.Diagnostics.Stopwatch = System.Diagnostics.Stopwatch.StartNew()
At any time you can then call the following code which you can subtract from your 30 minutes
_sw.Elapsed.TotalSeconds
To show this time constantly on a form you may need a second timer to update the screen that queries this value.

Related

vb.net - Timer stops working when stopped and started

I have an app that runs several timers.
The first is a heartbeat timer, HB_Timer, which fires off a backgroundworker at the set interval which runs a sql command to register a 'heartbeart'.
The second is a reinit timer, Reinit_Timer, which again fires off a backgroundworker to query global settings from the database and, if the value for heartbeat interval has changed, stops HB_Timer, changes HB_Timer.Interval accordingly and then restarts HB_Timer.
I've amended the code below slightly to put it in its most simplistic format.
The heartbeat interval in the DB is saved in seconds, so i multiply by 1000 to get ms before applying the interval...
Public Function Endpoint_ReInit()
Try
HB_Timer.Stop()
hb_interval = ReadSQLValue(<the data i need to read...>)
If hb_interval > 0 Then HB_Timer.Interval = (hb_interval * 1000)
HB_Timer.Start()
For some reason, once the timer is stopped, it wont start again programatically, and I can't see why.
I've added console.writeline on the tick event of the timer and on firing the backgroundworker... both work before it is stopped and then restarted and then neither work (obviously, if the first doesnt then the second definitely wont).
I wondered if it was going to quickly so have tried sleeping for periods between stopping and starting, but that didn't work.
I even tried adding a temp button on my form to see if the timer could be manually restarted, and that doesn't work either.
I have error handling on all my functions etc and no exceptions are thrown.
I'm at a bit of a loss.... can anyone help point me in the right direction?
At a guess the value returned from the SQL query is large, so it's not that the timer is stopped, it's just that it is taking a very long time before it ticks.
Or something crashes in your backgroundworker and thus your timer.Start() is never called (the call to ReadSQLValue() never returns). If ReadSQLValue() uses a BackgroundWorker, though I'm not really sure how you're managing the sync/async mixing, be aware that when a BackgroundWorker experiences an exception in DoWork() it doesn't may not end up in your code at the time it occurs. The BGW just fires the RunWorkerCompleted event with an EventArgs that has an exception in the Error property)
When I work with timers I tend to set them to some low interval, say 1 second, and if I want something to happen every minute for one process and two minutes for another I have a couple of ints that count down from 60/120 respectively and when they hit 0, I do the processes, and reset the ints back to 60/120. I don't stop/start/change the timer interval

How to Repeat Saving my Powerpoint file every 5 minutes?

I've been wanting to write a macro to automatically save my powerpoint file every 5 minutes. Can anyone help?
I know there's an auto-save built-in but that's only good for auto recover. I'm attempting to have this ppt being saved every 5 mins so that other users using it at the same time will see the updates come in (using Office 365).
Thanks!
I don't think you'll be able to do this with a simple macro, but you might be able to make it work with an add-in.
The add-in would:
Trap events, specifically the SelectionChanged event.
Every time the event fires, the event handling code compares the current time to the time it last fired (stored in a static variable).
If more than x minutes have elapsed since the event last fired, saves the presentation and resets the last-fired time.
If the event never fires during a session, it means that nothing changed, so no real reason to save.
A further refinement: before or after checking the time difference, check the presentation's .Saved property. If True, then nothing has changed in the presentation, so again, no reason to save.
I could be wrong, but most answers I've seen regarding saving in intervals use the OnTime method. This isn't actually available in PowerPoint, so I'm not actually sure that what you're wanting to do is possible.

How to make a message pop up based on a date user selected?

So I am doing a reminder tool in Visual Basic for myself and I added a MonthCalendar to the windows (check image). It runs great. User writes down the name and a date (in 24 hour format for now) and then when you click the add reminder, it registers it into the listbox and also writes it into a file so when user closes and opens the application, it stays there. When the time in my PC coincides with the one in the program, a message pops up. The only thing left I'm having trouble is with dates.
I want to be able to choose a date and a message popping at that day with the time. I know it might be simple, but for some reason I can't think of a way and searching around didn't help me.
Here's a snippet of the code I have for when the time coincides:
If (TimeValue(Now) = time) Then 'Dim time As String = l.Substring(0, 9)
MsgBox(msg)
End If
I thought using an If statement similar to this would work, but it tells me that dates really don't go well with boolean and I tried looking around the subfunctions, but I've yet to find any.
To be clear: The only thing I need is to be able to register the date. Here's an image of the designer view.
Design View
Use a Timer. Calculate how many milliseconds there are until the event and set the Interval of the Timer to that value. The maximum Interval value gives you just over 24 days. If you need more than that then simply set the Interval again when the Tick occurs. You keep going in jumps of ~24 days until you get to the event.

Disable a page in VB.net for a particular time

Im trying to disable a page which is opened while clicking a hyperlink in my application. My application is developed using VB.Net.
Can we use Timer function?
There are several ways to display a maintenance notification message. My preferred method is to use a database table called MaintenanceNotification.
Then, when you load the page, check the database for an existing notification, if there is one, handle appropriately.
**MaintenanceNotification**
MaintenanceNotificationId
StartDate
EndDate
Message
Comments
EDIT
To show a message at the same time every day, when the page loads, compare DateTime.Now.TimeOfDay to the time you want the messaged displayed (use a TimeSpan).
Psuedo Code:
If DateTime.Now.TimeOfDay is >= start time AND ALSO DateTime.Now.TimeOfDay <= end time THEN
'display the message.
END IF

Best way to save status of dynamic web interface

Basically in my website I have a sidebar with a stack of boxes; each box can be collapsed or expanded by the user. I need to save the status of each box for the currently logged in user.
I don't want to use cookies because if an user changes browser or computer, all the boxes will go to the default status.
Should I save this information on the database making a query every time the user collapses/expands a box? How would you handle this? Thanks.
Edit: What if an user clicks on the toggle button repeatedly, like ten times in two seconds, just because he enjoys the boxes' animation? He will make ten queries in two seconds. So maybe the question should be: when should I save this data?
Call a (client-side) "changed" function every time a box changes.
Keep two items of (client-side) state: the time the last update to the server was sent and whether a timer has been set.
Write a (client-side) "update" function that sends the update and updates the state to mark that the last update was just now.
When the changed function is called: if a timer is set, then return immediately; if an update has never been sent or the last update was sent more than ten seconds ago, then call the update function and return. Otherwise set a timer to send the update after ten seconds.
The timer callback should simply clear the timer flag and call the update function.
Also on an unload event check if a timer was set and if it was then clear the timer and call the timer callback function.
So the result is that you send the update immediately except when the user is flapping, in which case you only send an update every ten seconds at most.
There might be some cases where you lose an update, but this is likely to only happen if the user was playing with the toggling and then closed the page before the timer fired, in which case he probably won't notice anyway.
If you need to persist these options from multiple computers you will need some form of server side storage.
This could be database or flat file. The choice depends on what you have available, skill set, and the need to scale. If you are going to have just a few users, a flat file may be your best choice.