Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h4-Jun-08 3:51
N a v a n e e t h4-Jun-08 3:51 
GeneralRe: how to use event to re-write this code segment? Pin
George_George4-Jun-08 20:26
George_George4-Jun-08 20:26 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h5-Jun-08 6:47
N a v a n e e t h5-Jun-08 6:47 
GeneralRe: how to use event to re-write this code segment? Pin
George_George5-Jun-08 14:51
George_George5-Jun-08 14:51 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 17:49
mvePIEBALDconsult1-Jun-08 17:49 
GeneralRe: how to use event to re-write this code segment? Pin
George_George1-Jun-08 18:34
George_George1-Jun-08 18:34 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 19:12
mvePIEBALDconsult1-Jun-08 19:12 
GeneralRe: how to use event to re-write this code segment? Pin
George_George1-Jun-08 19:17
George_George1-Jun-08 19:17 
Thanks PIEBALDconsult,


Here is my code, please let me know if you think my code is the same as your ideas or not. I am using Event and Timer, but not semaphore. I want to learn from you about the new method.

class Program
{

    static AutoResetEvent CheckEvent = new AutoResetEvent(false);
    static bool stop = false;

    static void ThreadMethod2()
    {
        while (true)
        {
            CheckEvent.WaitOne();
            Console.WriteLine(DateTime.Now);
            if (stop)
            {
                break;
            }
            else
            {
                // do some work
            }
        }
    }

    static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        CheckEvent.Set();
    }

    static void Main(string[] args)
    {
        System.Timers.Timer aTimer = new System.Timers.Timer();
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        // Set the Interval to 5 seconds.
        aTimer.Interval = 5000;
        aTimer.Enabled = true;

        Thread worker = new Thread(new ThreadStart(ThreadMethod2));
        worker.Start();

        Console.WriteLine("Press \'q\' to quit the sample.");
        while (Console.Read() != 'q') ;

        stop = true;
        worker.Join();

        return;
    }
}



regards,
George
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 19:26
mvePIEBALDconsult1-Jun-08 19:26 
GeneralRe: how to use event to re-write this code segment? Pin
George_George2-Jun-08 0:52
George_George2-Jun-08 0:52 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult2-Jun-08 9:07
mvePIEBALDconsult2-Jun-08 9:07 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 1:36
George_George3-Jun-08 1:36 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult3-Jun-08 17:59
mvePIEBALDconsult3-Jun-08 17:59 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 18:27
George_George3-Jun-08 18:27 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult3-Jun-08 18:49
mvePIEBALDconsult3-Jun-08 18:49 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 19:00
George_George3-Jun-08 19:00 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult3-Jun-08 19:03
mvePIEBALDconsult3-Jun-08 19:03 
QuestionHow can I create own Browser? Pin
lockepeak1-Jun-08 14:08
lockepeak1-Jun-08 14:08 
AnswerRe: How can I create own Browser? Pin
Christian Graus1-Jun-08 15:54
protectorChristian Graus1-Jun-08 15:54 
QuestionReading Registry Key Problem. Pin
Jammer1-Jun-08 13:56
Jammer1-Jun-08 13:56 
AnswerRe: Reading Registry Key Problem. Pin
Sujith C Jose2-Jun-08 2:58
Sujith C Jose2-Jun-08 2:58 
QuestionCan I find out how many dataset are in a project? Pin
belzer1-Jun-08 11:20
belzer1-Jun-08 11:20 
AnswerRe: Can I find out how many dataset are in a project? Pin
Christian Graus1-Jun-08 15:54
protectorChristian Graus1-Jun-08 15:54 
GeneralRe: Can I find out how many dataset are in a project? Pin
belzer2-Jun-08 4:21
belzer2-Jun-08 4:21 
QuestionCan we declare method with optional parameters ? Pin
Mohammad Dayyan1-Jun-08 9:43
Mohammad Dayyan1-Jun-08 9:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.