none
delay in winforms with post request RRS feed

  • Question

  • Hi,

    Can someone give example how to make this. I have win form wich read from file and make post request to web. I want to put on form one text box where i can write how many seconds must sleep/wait after every request.

    for example:

    I run my app and read whole file with 2sec after every request. After finish i decide to run it again with 5sec delay after every request.

    Now i doing this in code side of my App with Thread.Sleep().


    • Edited by vins Wednesday, April 25, 2012 7:25 AM
    Wednesday, April 25, 2012 7:06 AM

Answers

  • Thread.Sleep(int.Parse(TextBoxTime.Text));
    • Edited by vins Wednesday, April 25, 2012 9:52 AM
    • Marked as answer by vins Wednesday, April 25, 2012 9:56 AM
    Wednesday, April 25, 2012 8:16 AM

All replies

  • Use a timer, for Windows Forms is the best one the Windows Forms Timer. 

    In your case is the best way to stop the timer when it Tick is throwed and to set the new interval then inside that tick event. 

    That gives your effect.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx


    Success
    Cor

    Wednesday, April 25, 2012 7:37 AM
  • Thread.Sleep(int.Parse(TextBoxTime.Text));
    • Edited by vins Wednesday, April 25, 2012 9:52 AM
    • Marked as answer by vins Wednesday, April 25, 2012 9:56 AM
    Wednesday, April 25, 2012 8:16 AM
  • If I understood you right:
    public partial class Form1 : Form
        {
            Timer T = new Timer();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                T.Interval = int.Parse(textBox1.Text) * 1000;
                T.Tick += new EventHandler(T_Tick);
                T.Start();
            }
    
            protected void T_Tick(object sender, EventArgs e)
            {
                T.Interval = int.Parse(textBox1.Text) * 1000;
                label1.Text = DateTime.Now.ToString("HH:mm:ss");
            }
            
        }


    Please mark as reply if helped.
    Also visit my blog http://msguy.net/

    Wednesday, April 25, 2012 10:05 AM