Thursday 15 November 2012

Creating Time Delay Programmatically C#

Creating Time Delay Programmatically C#


Wait a certain number of seconds before doing another action.


        void LightWait(int waitTime)

        {

            int curSecond = Convert.ToInt32(DateTime.Now.ToString("ss"));

            int newSec = curSecond + waitTime;

            if (newSec > 59)

            {

                newSec = newSec - 60;

            }

            while (!(Convert.ToInt32(DateTime.Now.ToString("ss")) == newSec))

            {

                Application.DoEvents();

            }

        }

Note:

Paste this into your main form. (Not in any other void)

To wait:
LightWait(10); //this will wait for 10 seconds.

1 comment:

  1. data visualization tool
    SQIAR (http://www.sqiar.com/solutions/technology/tableau) is a leading Business Intelligence company.Sqiar Provide Services Like Tableau Software Which help the company to present Information in Meaningful form.

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top