0

I have a scenario in which a parent thread spawns multiple task/job threads (done by someone else). At the end, I need to perform one additional task which is unrelated to the job threads.

What I need is to execute this new task (checking for existance of a file on a remove server) for as long as a fixed time, i.e. 30 minutes max, and to repeat the process in a fixed interval, i.e. every 2 minutes, until the condition is satisfied. If the confirmation is succeeded, it should exit back to the main thread (parent -- parent thread needs to wait for this particular task to conclude before terminating).

I am very new to C# multi-threading, if even we need threading for this case. So, can somebody give me a guidance.

Main thread
{
Child threads0...n
All Done

For as long as n minutes
(R) Every m minute, check for something
If succeed, exit
If not, continue waiting for m minute, then (R)
}
spender
  • 117,338
  • 33
  • 229
  • 351
Malvon
  • 1,591
  • 3
  • 19
  • 42
  • 1
    I'd advise against inventing a new programming language just for the purposes of telling us what you're trying to do. It isn't very clear. – spender Mar 19 '13 at 16:17
  • Possibly duplicate with this post: http://stackoverflow.com/questions/8771364/best-method-to-block-until-certain-condition-is-met – David Mar 19 '13 at 16:30

2 Answers2

1

Try something like this:

  Task.Factory.StartNew(() =>
  {
     while (!CheckForSomething())
        Task.Delay(TimeSpan.FromMinutes(2));

  }).Wait(TimeSpan.FromMinutes(30));
dmg
  • 608
  • 8
  • 15
  • Thank you dmg, and I apologize for not bringing this to the attention sooner, but I am running this against .NET 4.0, not 4.5 (Task.Delay() is not in .NET 4.0). – Malvon Mar 19 '13 at 17:55
1

There are several ways to do this, not listed exausted here, :)

Community
  • 1
  • 1
David
  • 15,894
  • 22
  • 55
  • 66