<?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[Timer als Thread erstellen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte die SetTimer(...) Funktion in einer Wrapper Klasse verpacken in der ich über das Publisher-Subscriber-Pattern Listener registrieren kann, die über das TimeEvent informiert werden sollen.</p>
<p>Ich möchte das die o. g. Wrapper-Klasse als Thread erstellt wird. Wie kann ich das denn realisieren ?</p>
<p>Ich habe im folgenden meine &quot;Timer.h&quot; und &quot;TimeEventListener.h&quot; anghängt. Meine bisjetzige &quot;TImer.cpp&quot; bzw. einzelne Implementierungen kann ich auf Anfrage ebenfalls posten.</p>
<p><strong>TimeEventListener.h</strong></p>
<pre><code class="language-cpp">#pragma once

class TimeEventListener
{
public:
	void PerformTimeOutEvent(void);
};
</code></pre>
<p><strong>Timer.h</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;list&gt;
#include &lt;map&gt;

#include &lt;iostream&gt;

#include &quot;TimeEventListener.h&quot;

using namespace std;

class Timer
{
private:

	unsigned int milliseconds;

	unsigned int id;

	list&lt;TimeEventListener*&gt; timeEventListeners;

	static map&lt;unsigned int, list&lt;TimeEventListener*&gt;*&gt; timeEventListenersMap;

public:

	Timer(unsigned int milliseconds);

	~Timer(void);

	void SetInterval(unsigned int milliseconds);

	unsigned int GetIntervall(void);

	void Start (void);

	void Stop (void);

	void InsertTimeEventListener(TimeEventListener* listener);

	void RemoveTimeEventListener(TimeEventListener* listener);

private:

	//Thread Methode
	static void StartThread (void* parameters)
	{
	}

	//Timer Methode
	static void CALLBACK PerformTimeEvent(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
	{
	}

};
</code></pre>
<p>Gruß und Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213783/timer-als-thread-erstellen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 09:52:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213783.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 May 2008 06:45:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Timer als Thread erstellen on Thu, 22 May 2008 06:45:19 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte die SetTimer(...) Funktion in einer Wrapper Klasse verpacken in der ich über das Publisher-Subscriber-Pattern Listener registrieren kann, die über das TimeEvent informiert werden sollen.</p>
<p>Ich möchte das die o. g. Wrapper-Klasse als Thread erstellt wird. Wie kann ich das denn realisieren ?</p>
<p>Ich habe im folgenden meine &quot;Timer.h&quot; und &quot;TimeEventListener.h&quot; anghängt. Meine bisjetzige &quot;TImer.cpp&quot; bzw. einzelne Implementierungen kann ich auf Anfrage ebenfalls posten.</p>
<p><strong>TimeEventListener.h</strong></p>
<pre><code class="language-cpp">#pragma once

class TimeEventListener
{
public:
	void PerformTimeOutEvent(void);
};
</code></pre>
<p><strong>Timer.h</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;list&gt;
#include &lt;map&gt;

#include &lt;iostream&gt;

#include &quot;TimeEventListener.h&quot;

using namespace std;

class Timer
{
private:

	unsigned int milliseconds;

	unsigned int id;

	list&lt;TimeEventListener*&gt; timeEventListeners;

	static map&lt;unsigned int, list&lt;TimeEventListener*&gt;*&gt; timeEventListenersMap;

public:

	Timer(unsigned int milliseconds);

	~Timer(void);

	void SetInterval(unsigned int milliseconds);

	unsigned int GetIntervall(void);

	void Start (void);

	void Stop (void);

	void InsertTimeEventListener(TimeEventListener* listener);

	void RemoveTimeEventListener(TimeEventListener* listener);

private:

	//Thread Methode
	static void StartThread (void* parameters)
	{
	}

	//Timer Methode
	static void CALLBACK PerformTimeEvent(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
	{
	}

};
</code></pre>
<p>Gruß und Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514035</guid><dc:creator><![CDATA[SoftwareEngineerer]]></dc:creator><pubDate>Thu, 22 May 2008 06:45:19 GMT</pubDate></item><item><title><![CDATA[Reply to Timer als Thread erstellen on Thu, 22 May 2008 07:54:22 GMT]]></title><description><![CDATA[<p>Ich hab keine Ahnung von dem C++ Quark, den du da brabbelst, aber was ist jetzt dein konkretes Problem? Zeig mir den Code und formuliere bitte dein Anliegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514051</guid><dc:creator><![CDATA[Wilhelm]]></dc:creator><pubDate>Thu, 22 May 2008 07:54:22 GMT</pubDate></item><item><title><![CDATA[Reply to Timer als Thread erstellen on Thu, 22 May 2008 09:12:58 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>also ich möchte den Timer mit dem Konstruktor erstellen und mit dem Zeitintervall in Millisekunden initialisieren können.</p>
<pre><code class="language-cpp">Timer(unsigned int milliseconds);
</code></pre>
<p>Die Klasse Timer soll aber auch ein Thread sein. Nur weiss ich nicht genau ob ich die Funktion</p>
<pre><code class="language-cpp">uintptr_t _beginthread( 
   void( __cdecl *start_address )( void * ),
   unsigned stack_size,
   void *arglist 
);
</code></pre>
<p>im Konstruktor von Timer aufrufen soll oder in der Methode</p>
<pre><code class="language-cpp">[
void Start (void);
/cpp]

Mit den Methoden

[cpp]
void InsertTimeEventListener(TimeEventListener* listener);

void RemoveTimeEventListener(TimeEventListener* listener);
</code></pre>
<p>soll man Referenzen von Klassen registrieren bzw. entfernen können, die von TimeEventListener ableiten. Sind diese Referenzen registriert wird vo jeder die Methode</p>
<pre><code class="language-cpp">void PerformTimeOutEvent(void);
</code></pre>
<p>aufgerufen und die Listener werden über das Zeit-Event informiert und können ihre Zeitgesteuerte Funktionalität ausführen.</p>
<p>Der Thread soll so lange ablaufen, bis die Methode</p>
<pre><code class="language-cpp">void Stop (void);
</code></pre>
<p>aufgerufen wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514094</guid><dc:creator><![CDATA[SoftwareEngineerer]]></dc:creator><pubDate>Thu, 22 May 2008 09:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to Timer als Thread erstellen on Thu, 22 May 2008 09:15:01 GMT]]></title><description><![CDATA[<p>Hier ist noch meine derzeitige Timer.cpp.</p>
<pre><code class="language-cpp">#include &quot;Timer.h&quot;

#include &lt;process.h&gt;

Timer::Timer(unsigned int milliseconds)
{
	this-&gt;SetInterval(milliseconds);
}

Timer::~Timer(void)
{
}

void Timer::SetInterval(unsigned int milliseconds)
{
	this-&gt;milliseconds = milliseconds;
}

unsigned int Timer::GetIntervall(void)
{
	return this-&gt;milliseconds;
}

void Timer::Start(void)
{
	unsigned int milliseconds = this-&gt;GetIntervall();
	unsigned int id = 1;
	SetTimer(NULL, id, milliseconds, &amp;(TIMERPROC)PerformTimeEvent);
	cout &lt;&lt; &quot;1&quot; &lt;&lt; endl;
	Timer::timeEventListenersMap.insert(make_pair(id, &amp;this-&gt;timeEventListeners));
	cout &lt;&lt; &quot;2&quot; &lt;&lt; endl;
	HANDLE thread = reinterpret_cast&lt;HANDLE&gt;(_beginthreadex(NULL, 0, StartThread, NULL, CREATE_SUSPENDED, id));
	cout &lt;&lt; &quot;3&quot; &lt;&lt; endl;
}

void Timer::Stop(void)
{
	unsigned int id = 1;
	KillTimer(NULL, id);
	Timer::timeEventListenersMap.erase(id);
}

void Timer::InsertTimeEventListener(TimeEventListener* listener)
{
	this-&gt;timeEventListeners.push_front(listener);
}

void Timer::RemoveTimeEventListener(TimeEventListener* listener)
{
	this-&gt;timeEventListeners.remove(listener);
}

map&lt;unsigned int, list&lt;TimeEventListener*&gt;*&gt; Timer::timeEventListenersMap;

int main (void)
{
	Timer timer = Timer(5000);
	timer.Start();
	return (0);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1514097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514097</guid><dc:creator><![CDATA[SoftwareEngineerer]]></dc:creator><pubDate>Thu, 22 May 2008 09:15:01 GMT</pubDate></item></channel></rss>