Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:30+00:00 2026-05-28T00:07:30+00:00

I am writing a program which will type a line of text in 5

  • 0

I am writing a program which will type a line of text in 5 second interval. Now, what I am trying to do is to add function which will type the text character by character with small spaces between each character. I am trying to use Thread.Sleep but I my program crashes, and I’m not sure why.

How to do this properly?

    private void Interval(object sender, EventArgs e)
    {
        if (cbPause.Checked == false)
        {
            SendKeys.Send(txtText.Text + "{enter}");

            if (tbType.SelectedTab == tbInterval) tmrInterval.Interval = int.Parse(nudInterval.Value.ToString());
            if (tbType.SelectedTab == tbRange) tmrInterval.Interval = random.Next(int.Parse(nudMin.Value.ToString()), int.Parse(nudMax.Value.ToString()));
        }
        else if (cbPause.Checked == true)
        {
            Random random = new Random();

            foreach (char character in charList)
            {
                SendKeys.Send(character.ToString());
                Thread.Sleep(1000);
            }

            SendKeys.Send("{enter}");
        }
    }

    private void btnStart_Click(object sender, EventArgs e)
    {
        if (txtText.TextLength < 1 || txtText.Text == string.Empty)
        {
            lblMessage.Text = "You must type text to proceed!";
            btnStart.Enabled = false;
        }
        else
        {
            foreach (char character in txtText.Text)
            {
                charList.Add(character);
            }

            if (tbType.SelectedTab == tbInterval)
            {
                tmrDelay.Enabled = true;

                txtText.Enabled = false;
                nudInterval.Enabled = false;
                nudMin.Enabled = false;
                nudMax.Enabled = false;
                btnStart.Enabled = false;
                btnStop.Enabled = true;
            }

            if (tbType.SelectedTab == tbRange)
            {
                tmrDelay.Enabled = true;
                tbType.Enabled = false;
                txtText.Enabled = false;
                nudInterval.Enabled = false;
                nudMin.Enabled = false;
                nudMax.Enabled = false;
                btnStart.Enabled = false;
                btnStop.Enabled = true;
            }

            lblMessage.Text = "Starting auto typing in: 3";
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:07:31+00:00Added an answer on May 28, 2026 at 12:07 am

    If you call Thread.Sleep, this is going to hang your GUI thread.

    What I would do, is use a System.Windows.Forms.Timer, and every Tick, have it type the next character.

    public partial class Form1 : Form
    {
        Timer timer;
        string str;
        int char_num;
    
        public Form1()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Tick += timer_Tick;
        }
    
        void timer_Tick(object sender, EventArgs e)
        {
            SendKeys.Send(str.Substring(char_num++, 1));
            if (char_num == str.Length)
                timer.Stop();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Focus();
            str = "Jonathon";
            char_num = 0;
            timer.Interval = 1000;
            timer.Start();
        }
    }
    

    Note: If it’s not obvious, this code requires a form with a textBox1 and a button who’s Click event is wired to button1_Click().

    If you want the first character to be sent right away, you can “cheat” by calling the Tick handler right away when you start the timer, by adding the following line:

    timer_Tick(null, EventArgs.Empty);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program in Ruby which will search for strings in text
I'm writing a small program which will make a GET request to a server
I am writing a program which will tokenize the input text depending upon some
I was writing a command line program which will have a status bar, much
I'm writing a program which will use scan conversion on triangles to fill in
I'm writing a program which will allow to load a specific managed .DLL file
Right now I am writing a simulation program which output is formatted according to
I'm about to start writing a program which will attempt to extract data from
I am writing a c++ program which sooner or later will need to be
I'm currently writing a program which will need to incorporate writing its output to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.