title: Some questions about System.Threading.Timer and Parallel
body: <p>I would like to start some of my functions every x second. But I dont want to wait for any function until its done before Im starting the function again. Let say I set the timer to 5 sec and I start <code>functionX()</code> and after 5 sec <code>functionX()</code> is not done => I want to start <code>functionX()</code> again in a new thread. I also want that a group of functions are starting at the same time.</p>
  
  <p>Thats why I thought I have to use <code>System.Threading.Timer</code> and <code>Parallel</code> Lets write a short example, I thought this is how it should be:</p>
  
  <pre><code>class Program
      {
          private static System.Threading.Timer timer;
          private static int interval = 2000;
  
          static void Main(string[] args)
          {
              Console.WriteLine("go");
              Run();
              Console.WriteLine("end");
              Console.ReadKey();
          }
  
          private static void Run()
          {
              timer = new System.Threading.Timer(TimerCallback, null, 0, interval);
          }
  
          private static void TimerCallback(Object o) {
              Parallel.Invoke(() =&gt; FunctionA(), () =&gt; FunctionB(), () =&gt; FunctionC());
          }
  
          private static void FunctionA()
          {
              Console.WriteLine("A");
          }
  
          private static void FunctionB()
          {
              Console.WriteLine("B");
          }
  
          private static void FunctionC()
          {
              Console.WriteLine("C");
          }
      }
  </code></pre>
  
  <p>Is this alright? Any suggestions? Even if this code is somehow wrong: I would like to ask another question about my output - if I start this Code I get something like this as output:</p>
  
  <pre><code>go
  end
  A
  B
  C
  C
  A
  B
  C
  A
  B
  C
  B
  A
  </code></pre>
  
  <p>Uhm. The first output <code>go</code> is fine, but why is the second one <code>end</code> , why not <code>A</code>,<code>B</code>,<code>C</code>? And is that normal, that the output A,B,C is somehow after the first output random?</p>
  
  <p>The next problem what I dont understand: if I remove the line                 <code>Console.ReadKey();</code> I cannot see any output. </p>
  
  <pre><code>        static void Main(string[] args)
          {
              Console.WriteLine("go");
              Run();
              Console.WriteLine("end");
          }
  </code></pre>
  
  <p>I mean the consol is starting but after some millisec its closed and its not opening again. But it should be appear because Im calling A,B,C again and again, so a new consol should appear again and again. Any ideas? Thank you</p>