title: Making a multi-threaded timer in C++ Builder using the Win32 API
body: <p>I have an application that runs in the main thread. Now I need to start a new thread with a Timer event which has to call a method periodically, every 5 minutes. In that, I need to print the status of the main thread. Even if the main thread dies. I need this second thread to be alive print that the main thread died or had an exception.</p>
  <p>I tried out examples, but I don't know how to call the Timer interval, ie I don't know how to implement the periodical call.</p>
  <p>Below is the sample code snippet I tried:</p>
  <pre><code>#include &lt;vcl.h&gt;
  #include &lt;windows.h&gt;
  
  #pragma hdrstop
  #pragma argsused
  
  #include &lt;tchar.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;process.h&gt;
  #include &lt;time.h&gt;
  
  #pragma comment(lib, &quot;Winmm.lib&quot;)
  
  void Thread_Start(void*);
  
  int _tmain(int argc, _TCHAR* argv[])
  {
     _beginthread(Thread_Start, 10000, NULL);
     printf(&quot;/n RS&quot;);
     //   getchar();
     //   return 0;
  }
  
  int i = 0;
  void Thread_Start(void*)
  {
    while (i &lt;50)
    {
      printf(&quot;/n Thread Started&quot;);
      i++;
      break;
    }
  }
  </code></pre>