locked
Design for creating a stop clock without using Threading RRS feed

  • Question

  • User229603173 posted

    Hi All,

    I was trying to creating a stop clock by using C# ,

    could any one help me to design the stop clock without using the concept of threads

    thanks

    Chezhian

     

    Thursday, May 30, 2013 11:41 AM

Answers

  • User-488622176 posted

    No. Not possible :-)

    When you have a UI such as Winforms or WPF, your UI us running in a thread that is responding to user input. If you want to use this thread to countdown for a stop clock, you block the UI thread. This implies your UI will get blurry (lacking refresh). This results in a ver bad look & feel.

    Unless you want to do it in javascript & HTML. But underneath, it runs multithreaded.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 30, 2013 5:02 PM
  • User-525215917 posted

    As Illeris suggested you freeze UI thread and it's not good if you are writing UI application. Otherwise you can use loop like this:

    while(someCondition)
    {
        doSomething();
        Thread.Sleep(1000);
    }

    Thread.Sleep makes sure your loop is not consuming 100% of CPU (try out what while(true) {} does when run) and gives control to other running code meanwhile. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 31, 2013 1:11 PM

All replies

  • User-488622176 posted

    No. Not possible :-)

    When you have a UI such as Winforms or WPF, your UI us running in a thread that is responding to user input. If you want to use this thread to countdown for a stop clock, you block the UI thread. This implies your UI will get blurry (lacking refresh). This results in a ver bad look & feel.

    Unless you want to do it in javascript & HTML. But underneath, it runs multithreaded.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 30, 2013 5:02 PM
  • User-525215917 posted

    As Illeris suggested you freeze UI thread and it's not good if you are writing UI application. Otherwise you can use loop like this:

    while(someCondition)
    {
        doSomething();
        Thread.Sleep(1000);
    }

    Thread.Sleep makes sure your loop is not consuming 100% of CPU (try out what while(true) {} does when run) and gives control to other running code meanwhile. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 31, 2013 1:11 PM