Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# timer

George SteevesGeorge Steeves Posts: 8Member
Is there an easy way to do in C# what I would do in C++ with
delay(1000);

Comments

  • weiccoweicco Posts: 950Member
    : Is there an easy way to do in C# what I would do in C++ with
    : delay(1000);
    :

    System.Threading.Thread.CurrentThread.Sleep(1000);

    But this is deprecated. You should create some waitable object and wait for it. Also this is pretty evil since your thread is suspended for a while and it can't for example process any messages.
  • George SteevesGeorge Steeves Posts: 8Member
    : : Is there an easy way to do in C# what I would do in C++ with
    : : delay(1000);
    : :
    :
    : System.Threading.Thread.CurrentThread.Sleep(1000);
    :
    : But this is deprecated. You should create some waitable object and wait for it. Also this is pretty evil since your thread is suspended for a while and it can't for example process any messages.
    :



  • George SteevesGeorge Steeves Posts: 8Member
    : : : Is there an easy way to do in C# what I would do in C++ with
    : : : delay(1000);
    : : :
    : :
    : : System.Threading.Thread.CurrentThread.Sleep(1000);
    : :
    : : But this is deprecated. You should create some waitable object and wait for it. Also this is pretty evil since your thread is suspended for a while and it can't for example process any messages.
    : :
    :
    :
    :
    :
    Now I get?

    Static member 'System.Threading.Thread.Sleep(int)'
    cannot be accessed with an instance reference;
    qualify it with a type name instead

    Tnx for the help.

  • weiccoweicco Posts: 950Member
    : : : : Is there an easy way to do in C# what I would do in C++ with
    : : : : delay(1000);
    : : : :
    : : :
    : : : System.Threading.Thread.CurrentThread.Sleep(1000);
    : : :
    : : : But this is deprecated. You should create some waitable object and wait for it. Also this is pretty evil since your thread is suspended for a while and it can't for example process any messages.
    : : :
    : :
    : :
    : :
    : :
    : Now I get?
    :
    : Static member 'System.Threading.Thread.Sleep(int)'
    : cannot be accessed with an instance reference;
    : qualify it with a type name instead
    :
    : Tnx for the help.
    :
    :

    Thread.CurrentThread.Sleep ...
  • tsagldtsagld Posts: 621Member
    : : : : : Is there an easy way to do in C# what I would do in C++ with
    : : : : : delay(1000);
    : : : : :
    : : : :
    : : : : System.Threading.Thread.CurrentThread.Sleep(1000);
    : : : :
    : : : : But this is deprecated. You should create some waitable object and wait for it. Also this is pretty evil since your thread is suspended for a while and it can't for example process any messages.
    : : : :
    : : :
    : : :
    : : :
    : : :
    : : Now I get?
    : :
    : : Static member 'System.Threading.Thread.Sleep(int)'
    : : cannot be accessed with an instance reference;
    : : qualify it with a type name instead
    : :
    : : Tnx for the help.
    : :
    : :
    :
    : Thread.CurrentThread.Sleep ...
    :
    No, the Sleep method is static:
    [code]
    System.Threading.Thread.Sleep(1000);
    [/code]

    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • weiccoweicco Posts: 950Member

    : No, the Sleep method is static:
    : [code]
    : System.Threading.Thread.Sleep(1000);
    : [/code]
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :

    OMG! I could've sworn it is non-static but you are absolutely right. Well, I've been known to make mistakes from time to time :)
Sign In or Register to comment.