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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:30:33+00:00 2026-05-16T12:30:33+00:00

I want to scan a queue every 10 seconds using a Timer. If there

  • 0

I want to scan a queue every 10 seconds using a Timer. If there are more then 0 items in this queue then Deque the first one, pass it as an argument to a Process and run that process. The timer should be disabled while this process executes. Once the process exits, it should re-enable the timer.

The items in the queue can be added manually or can come from a database.

The following C# code does not works after the first process is finished. For some reason the timer is not enabled again. Can somebody help?

public MainForm()
{
    InitializeComponent();

    queue = new Queue<string>();
    process = new Process();
    process.Exited += new EventHandler(Process_Exited);
    process.EnableRaisingEvents = true;
}

void StartProcess(string args)
{
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = @"C:\Program Files\My Software\RunProcess.exe";
    psi.Arguments = args;
    psi.WindowStyle = ProcessWindowStyle.Minimized;

    process.StartInfo = psi;
    process.Start();
}

void Process_Exited(object sender, EventArgs e)
{
    timer.Enabled = true;
}

void Timer_Tick(object sender, EventArgs e)
{
    if (queue.Count > 0)
    {
        timer.Enabled = false;
        StartProcess(queue.Dequeue());
    }
}
  • 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-16T12:30:34+00:00Added an answer on May 16, 2026 at 12:30 pm

    I didn’t look up the details for lack of time but I found out that dispatching timer.Enabled = true; to the UI thread will do the trick.

    EDIT: Just checked MSDN: “This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread. “

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

Sidebar

Related Questions

Let's say I want to scan through every file in this directory (recursive, too).
I an using Zbar SDK and want to scan QRcode and barcode in my
I've started using Autofac and want to scan some DLL's and get Autofac to
i have many documents that i want to scan. every document will have about
I want to scan a website using jQuery, but the ID is constantly changing,
Considering a really huge file(maybe more than 4GB) on disk,I want to scan through
I want to scan to all RecordSource in my ADP Forms. One of my
I'm not sure, is this possible or not? I want to scan barcode from
I want to scan this string hello I am emp 1313 object of string
please help me with this. i want to scan array1 through elements of array2

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.