c# - Class Events Triggering Actions in Main Program -


i have used solution stated in question.

i want reuse timer methods in several different forms , have been trying create class keep number of methods in various forms minimum. new programming , using classes , events , don't quite think approaching correctly.

below class far. can , event in class trigger , event in main program? should using class?

using system; using system.timers;  namespace tmp_erp {     class timer     {         int milliseconds;         system.windows.forms.timer querytimer;          public timer()         {         }           //revokes timer if not revoked         public void revokequerytimer()         {             if (querytimer != null)             {                 querytimer.stop();                 querytimer.tick -= querytimer_tick;                 querytimer = null;             }         }          public void restartquerytimer()         {             //start or reset pending query             if (querytimer == null)             {                 querytimer = new system.windows.forms.timer { enabled = true, interval     = 1500 };                 querytimer.tick += querytimer_tick;             }              else             {                 querytimer.stop();                 querytimer.start();             }         }          void querytimer_tick(object sender, eventargs e)         {             //tells main program something?         }     } } 

each time types character call restartquerytimer(). if querytimer ticks query database , call revokequerytimer() remove timer.

the best example can have in situation interface of timer you're using inside timer - system.windows.forms.timer. provide event notify client of class internal timer does.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -