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 6322021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:16+00:00 2026-05-24T16:15:16+00:00

I’m back again … already. As the second part to my program, I need

  • 0

I’m back again … already.

As the second part to my program, I need to be able to pause my program at random intervals – for example, 10 minutes into the program it gets paused for 20 seconds, 47 minutes in it gets paused for 3 minutes 49 milliseconds … something like that. I’m not going to attempt a shot at this yet as all the stuff I’ve found seems to be way too complicated for my tiny little brain to understand, so if someone could break it down for me, that would be great.

Below is my code, I need to pause the bit in the for loop. Thanks!
Also, I do know that I’ve got it clicking, sleeping, clicking, sleeping and then repeating the loop – I want it like that 🙂

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;

namespace MagicMouse
{
    public partial class Form1 : Form
    {
        //all this stuff has to do with being able to actually click a mouse
        //[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
        //public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

        [DllImport("user32.dll")]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        //this function will click the mouse using the parameters assigned to it
        public void DoMouseClickLeft()
        {
            //Call the imported function with the cursor's current position
            int X = Cursor.Position.X;
            int Y = Cursor.Position.Y;
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        }

        public void NumberCheck(string ValidateNum)
        {
            long CanConvertOut = 0;
            bool CanConvertBool = long.TryParse(ValidateNum, out CanConvertOut);
            if (CanConvertBool == false)
            {
                MessageBox.Show("Please enter a valid number.");
                return;
            }
        }

        //this generates the random number used for sleep timer
        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        //button 1 is start clicking
        private void button1_Click(object sender, EventArgs e)
        {
            //this section sends data to the number validation function
            string ValidateNum = NumberOfItems.Text;
            NumberCheck(ValidateNum);
            int Clicks = Convert.ToInt16(NumberOfItems.Text);

            for (int i = 1; i < Clicks; i++)
            {
                int SleepTime1 = RandomNumber(819, 1092);
                DoMouseClickLeft();
                Thread.Sleep(SleepTime1);
                DoMouseClickLeft();
                Thread.Sleep(SleepTime1);
            }
        }

        //button 2 is exit
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();

        }


    }
}
  • 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-24T16:15:17+00:00Added an answer on May 24, 2026 at 4:15 pm

    Try something like this:

    private DateTime GetNextSleep()
    {
        // Between 3 and 20 minutes, adjust as needed.
        return DateTime.Now + new TimeSpan(0, 0,
            RandomNumber(60 * 3, 60 * 20));
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        //this section sends data to the number validation function
        string ValidateNum = NumberOfItems.Text;
        NumberCheck(ValidateNum);
        int Clicks = Convert.ToInt16(NumberOfItems.Text);
    
        DateTime nextSleep = GetNextSleep();
    
        for (int i = 1; i < Clicks; i++)
        {
            int SleepTime1 = RandomNumber(819, 1092);
            DoMouseClickLeft();
            Thread.Sleep(SleepTime1);
            DoMouseClickLeft();
            Thread.Sleep(SleepTime1);
    
            if (DateTime.Now >= nextSleep)
            {
                // Sleep between 1 and 5 minutes, adjust as needed.
                Thread.Sleep(new TimeSpan(0, 0,
                    RandomNumber(60 * 1, 60 * 5)));
    
                nextSleep = GetNextSleep();
            }
        }
    }
    

    Basically, you pre-compute the time you want to pause. Once that time arrives, you sleep for a random amount of time, compute the next sleep time, and return to the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.