Advertisement
parseint32

Esempio di EventArgs - Filippo Tortomasi

Mar 28th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     public class BohEventArgs : EventArgs
  9.     {
  10.         public DateTime oraCorrente { get; set; }
  11.         public BohEventArgs(DateTime o) { oraCorrente = o; }
  12.         public override string ToString()
  13.         {
  14.             return oraCorrente.Hour + ":" + oraCorrente.Minute;
  15.         }
  16.     }
  17.  
  18.     class Program
  19.     {
  20.         public static event Action<EventArgs> sonoDieci;
  21.         static void Main(string[] args)
  22.         {
  23.             int conta = 0;
  24.             sonoDieci += (ora) =>
  25.                 {
  26.                  
  27.                     Console.WriteLine("Sono passati 10 secondi, e sono le ore: " + ora.ToString());
  28.                     conta = 0;
  29.                 };
  30.             System.Timers.Timer a = new System.Timers.Timer(1000);
  31.             a.Start();
  32.             a.Elapsed += (o, e) =>
  33.                 {
  34.                     if (sonoDieci != null && conta == 10) sonoDieci(new BohEventArgs(DateTime.Now));
  35.                     conta++;
  36.                 };
  37.             Console.ReadKey();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement