Link to home
Start Free TrialLog in
Avatar of ahashash
ahashash

asked on

how to stop endless MsgBox due to timer? wihtout stopping timer permenantly.

Hi, i am making an application (Winform) using VS2010 ultimate, (VISUAL BASIC), My apologies for this is a bit long.
i tried searching all over but to no avail...

the application basically:
stores staff index information in a DB(ms Access), (fire safety training date every 6 months, patient care awareness date every year, bio-hazard safety training date every 10 months,  other dates that vary in the time they must take place....) all working fine, so far.

Objective: (works fine)
I need the application to be running in the background, i mean the task bar when minimized, i used a notifyIcon, works great, another thing, which is the point of this whole app, is that while minimized and running i placed a timer that is even displayed and counting date and time(dd-mm-yy HH:mm:ss) and so, what i want is that when the next date comes for lets say, fire_safety which is 6 months from the previous one a message box should appear even while minimized to tray to alert the user (many staff and cannot keep track just by opening every day to check!) then user presses OK then they can set a new date or leave it, does not matter so long as they are notified, anyway,

what i did (works fine):
first off, i used my own form as a message box with ok button only.
i used DateDiff, so as to check if the difference between the original or past fire safety date and the "supposedly" next one is more than 6 months then display a MsgBox "staff needs to set a date or BLAH bla..."...

THE PROBLEM:
well first i tried with minutes not months, to see if it is working when teh timer hits a certain value or time....
so, when the time comes, and the event is fired, a MsgBox is displayed, but as soon as i press OK, it comes up again and OK then again pops up...and so forth ..!!!????

What i tried:
im using a form as a MSgBox did not work
iused another timer for a separate evet or for the message box to close but i find that i am forced to place the msgbox in that condition i want triggered so its affected by the timer and loops.
i tried stopping the timer BEFORE the MSgBox, or disposing or myTimer.Disable=true any where in the form, but i get stuck coz one thing works and another fails...
i almost give up, i hope some one can help please.

i will attach a sample code of what is happening....and ya sorry on a side note i used (had to use a button activate the timer or enable it, dont know why but had to!)

Many thanks......

myTimer-code.txt
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

You have to use some sort of flag to track if the reminder has been shown (eg. bool field in a table), not show it each time the timer is hit - you have found out what happens in that case.
when the timer was detected you have to kill the timer such to stop the timer action until you get further directive by the user. then you may place some kind of 'alert' icon to a suitable place and when the user clicked on the icon you may open a dialog or message box to ask for further action where you might create a new timer for the next period.

Sara
Avatar of ahashash
ahashash

ASKER

well actually i do have like a picture box that shows red or green circles to indicate if the date is past due or near or whatsoever and works fine, only thing is a messageBox that if showed then it keeps popping up because of the timer, and so if i stop the timer, then it will work one time, so i cannot restart the timer, if i did it will re-loop the popping of the msgbox... catch-22 i guess, im really stuck
i thought of the flag idea but dont really know how to implement ..
i was thinking maybe i can pause the timer do the event and resume timer, sure will raise the popping of msgbox again..
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you could kill the first timer and create a new one (with a different event id) which is responsible to handle the reminder and further actions. your problem is that you want to handle it with one timer what could not work beside you store information persistently somewhere in a database or inifile or registry (what you need to do anyhow if the program could be exited without an appropriate action by the user and must be resumed at next program start).

Sara
One timer or many is irrelevant.  
If a reminder is required then that must come from some sort of permanent storage, here there is an access database with this information.
What the app is to do, if I understand correctly, is remind the user and then log their response to that reminder.
Agreed...the flag definitely needs to be stored per "event" in the database.
Many thanks, i tried using a flag but did not know it should be used in teh database, so, i will try using it in the database, but just a small question though, will you please correct my sort of psuedo code here in regards to this matter;

private sub mytimer .............handles mytimer.tick
        if the whatever-flag (that is stored in the DB)- is SHOWN beside/for the fire safety_datetimepicker then
           msgbox "firesafety training is due/ or past due...."
           ' blah other blah
        else
           exit sub
        end if
end sub

could it be somthing like that? many many thanks
sorry for the trouble.............
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial