Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!