Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Fetch Running Task by ID

I have created a function as follows

public int ManFunction()
{
    Task task = Task.Factory.StartNew(RunTask, cts_token.Token);
    return task.Id;
}

Is there any way to get running task by task-Id in C#?

basically, when do I call function a second time I want to check whether the task is running or not? based on that I want to pass a notification to the user that the task is already running.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Using Task.Id to as identifiers bad idea. Task.Id is not unique see remarks here

Your function instead of id can return Task:

public Task ManFunction()
{
    Task task = Task.Factory.StartNew(RunTask, cts_token.Token);
    return task;
}

Basically you can work with Task object like with id, no difference to you. Than you can use task.IsCompleted to check is task done or not, like:

var t = this.ManFunction();
//.....
if (!t.IsCompleted)
{
    //.....
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda