<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Thread&#x2F;Timer Problem]]></title><description><![CDATA[<p>Hallo zusammen,<br />
habe gerade ein merkwürdiges Problem.<br />
Meine Anwendung erzeugt einen neuen Thread. Dieser Thread erstellt einen Timer. Jedoch wird die angegebene Timer-Prozedur nicht durchlaufen. Erstelle ich den Timer im Hauptthread, dann funktioniert alles wunderbar.</p>
<p>Hier mal etwas Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime );
DWORD WINAPI ThreadProc( LPVOID pParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPSTR lpCmdLine, int nCmdShow )
{
  MSG msg;
  HANDLE hThread;
  DWORD dwThreadId;

  hThread = CreateThread( NULL, 0, ThreadProc, NULL, 0, &amp;dwThreadId );

  while ( GetMessage( &amp;msg, NULL, 0, 0 ) )
  {
    TranslateMessage( &amp;msg );
    DispatchMessage( &amp;msg );
  };
};

VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
  int i = 0;

  while ( i &lt; 100 )
  {
    i++;
  };
};

DWORD WINAPI ThreadProc( LPVOID pParam )
{
  SetTimer( NULL, NULL, 100, TimerProc );

  while ( 1 )
  {
    Sleep( 10 );
  };

  ExitThread( 0 );
  return 0;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/106117/thread-timer-problem</link><generator>RSS for Node</generator><lastBuildDate>Mon, 29 Jun 2026 20:12:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/106117.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Apr 2005 09:27:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Thread&#x2F;Timer Problem on Wed, 06 Apr 2005 09:33:40 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
habe gerade ein merkwürdiges Problem.<br />
Meine Anwendung erzeugt einen neuen Thread. Dieser Thread erstellt einen Timer. Jedoch wird die angegebene Timer-Prozedur nicht durchlaufen. Erstelle ich den Timer im Hauptthread, dann funktioniert alles wunderbar.</p>
<p>Hier mal etwas Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime );
DWORD WINAPI ThreadProc( LPVOID pParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPSTR lpCmdLine, int nCmdShow )
{
  MSG msg;
  HANDLE hThread;
  DWORD dwThreadId;

  hThread = CreateThread( NULL, 0, ThreadProc, NULL, 0, &amp;dwThreadId );

  while ( GetMessage( &amp;msg, NULL, 0, 0 ) )
  {
    TranslateMessage( &amp;msg );
    DispatchMessage( &amp;msg );
  };
};

VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
  int i = 0;

  while ( i &lt; 100 )
  {
    i++;
  };
};

DWORD WINAPI ThreadProc( LPVOID pParam )
{
  SetTimer( NULL, NULL, 100, TimerProc );

  while ( 1 )
  {
    Sleep( 10 );
  };

  ExitThread( 0 );
  return 0;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/760913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/760913</guid><dc:creator><![CDATA[Herrmann]]></dc:creator><pubDate>Wed, 06 Apr 2005 09:33:40 GMT</pubDate></item><item><title><![CDATA[Reply to Thread&#x2F;Timer Problem on Wed, 06 Apr 2005 09:44:44 GMT]]></title><description><![CDATA[<p>Jeder thread hat seine eigene message queue. Die timer message langed also in der message queue von thread 2 nicht von thread 1, was bedeutet es passiert gar nix damit da thread 2 keine message loop zum abarbeiten hat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/760929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/760929</guid><dc:creator><![CDATA[CMatt]]></dc:creator><pubDate>Wed, 06 Apr 2005 09:44:44 GMT</pubDate></item><item><title><![CDATA[Reply to Thread&#x2F;Timer Problem on Wed, 06 Apr 2005 09:47:39 GMT]]></title><description><![CDATA[<p>Hi CMatt, habe ich auch gerade gefunden. Eigendlich einleutend oder <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/760931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/760931</guid><dc:creator><![CDATA[Herrmann]]></dc:creator><pubDate>Wed, 06 Apr 2005 09:47:39 GMT</pubDate></item></channel></rss>