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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:24:01+00:00 2026-05-13T07:24:01+00:00

I have a thread, within this thread I call a method which takes a

  • 0

I have a thread, within this thread I call a method which takes a long time to process.

The method has a foreach using a counter for each iteration (counter++)

I want to do this:

  • Within foreach, if counter > 20:
    • Check if any proccess with name = “SendMailService.exe” is executing.
    • If NOT executing, launch using process.start(sendmailservice.exe);
    • If executing wait 3 minutes and then check again.
  • After the foreach code
    • Check if any proccess with name = “SendMailService.exe” is executing.
    • If process is executing, wait until the process finished.

Anybody can understand me? any help will be appreciated.

My code is:

private void bEnviarAleatorioSeleccionados_Click(object sender, EventArgs e)
{
    CrossThreadCalls();

    this.bEnviarAleatorioSeleccionados.Enabled = false;

    // Threads werden erzeugt
    Thread hiloMain = new Thread(
        new ThreadStart(EnviarAleatorioSeleccionadosYEnviarCorreo));
    hiloMain.Start(); // Threads werden gestartet
}

private void EnviarAleatorioSeleccionadosYEnviarCorreo()
{
    string rutaFicheroMp3 = GetRutaFicheroMp3DeLoquendo(textoLoquendo);

    int contador = 0;
    foreach (ListViewItem item in lstRecientes.Items)
    {
        if (item.Checked)
        {
            contador++;
            EnviarCorreoParaElementoListView(item, rutaFicheroMp3, item.Text);
        }

        // DO THE CHECK HERE, EACH 3 MINUTES (TIMER) !!!! HOW ????????
        if (contador > 20)
        {
            var listaP = Process.GetProcesses().FirstOrDefault(
                p => p.ProcessName == "ServicioEnvioCorreo.exe");
            if (listaP == null)
            {
                // Iniciar Envio de Correo
                EnviarCorreosPorProceso();
            }
        }
    }

    EliminarFicheroLoquendo(rutaFicheroMp3);
    this.bEnviarAleatorioSeleccionados.Enabled = true;
}
  • 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-13T07:24:01+00:00Added an answer on May 13, 2026 at 7:24 am

    Well, two things:

    Since you’re doing this on a separate thread anyways:

    // DO THE CHECK HERE, EACH 3 MINUTES (TIMER) !!!! HOW ???????? 
    if (contador > 20)  { ... }
    

    You could easily just block the thread for your 3 minute check, instead of using a timer. A simple Thread.Sleep(180000); will put a 3 minute delay into your loop.

    That being said, I’d question whether this is really the best approach to this problem. Since you’re starting the process yourself, you could attach a handler to the Process.Exited event, and “restart” the process after it exits. This would eliminate the entire need for the loops, checks, and probably even the entire separate thread. Just start the process, and when it exists, restart it (20x).

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

Sidebar

Related Questions

All, I have a long running process that I run on a background thread
In Java I have the necessity of implementing a class that extends Thread within
I have thread where downloading xml file a this xml file i want to
I have a thread which needs to be run in the background every 1000ms.
So I have the following code in a method which I want to set
Thanks for your time and sorry for this long message! My work environment Linux
I have a class that has two method in it, one calls a class
I have a method to generate fully qualified URLs that I wrote which I
I have a background thread loading data which I want to display in an
I am currently using JMX to manage and monitor a huge migration process which

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.