<?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[TEvent: WaitFor abbrechen]]></title><description><![CDATA[<p>Folgendes kleine Beispielprogramm:</p>
<pre><code class="language-cpp">#include &lt;vcl&gt;
#include &quot;syncobjs.hpp&quot;
#include &lt;memory&gt;
#include &lt;iostream&gt;

std::auto_ptr&lt; TEvent&gt; pEvent;

class Foo
:public TThread
{
public:
  Foo()
  :TThread( false)
  {
  }

  virtual void __fastcall Execute(void)
  {
    pEvent-&gt;WaitFor( INFINITE);  //kein Timeout

    std::cout &lt;&lt; &quot;Event beendet&quot;&lt;&lt;std::endl;  //hier komm ich nie hin
  }
};

int main()
{

  pEvent.reset( new TEvent( NULL,  //Standard-Sicherheitsattribute0
                            true,  //manuelles Reset
                            false, //signal beim Start nicht gesetzt
                            &quot;&quot;));

  std::auto_ptr&lt; Foo&gt; pFoo( new Foo);

  MessageBox( NULL,&quot;Warten&quot;,&quot;Warten&quot;, MB_OK);

  pEvent.reset( NULL);   //TEvent-Objekt wird zerstört -&gt; es müsste in Execute-Funktion weitergehen!

  Sleep( 10000);

  return 0;
}
</code></pre>
<p>Lt. Hilfe zu TEvent::WaitFor kehrt es mit 'wrAbandoned' wenn das &quot;Ereignisobjekt [...] gelöscht [wurde], bevor das Timeout-Intervall verstrichten ist&quot;</p>
<p>in der Zeile 'pEvent.reset( NULL);' lösche ich das Ereignis-Objekt, trotzdem komm ich nie über das WaitFor hinaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/117814/tevent-waitfor-abbrechen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 17:30:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/117814.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Aug 2005 14:02:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 14:28:19 GMT]]></title><description><![CDATA[<p>Folgendes kleine Beispielprogramm:</p>
<pre><code class="language-cpp">#include &lt;vcl&gt;
#include &quot;syncobjs.hpp&quot;
#include &lt;memory&gt;
#include &lt;iostream&gt;

std::auto_ptr&lt; TEvent&gt; pEvent;

class Foo
:public TThread
{
public:
  Foo()
  :TThread( false)
  {
  }

  virtual void __fastcall Execute(void)
  {
    pEvent-&gt;WaitFor( INFINITE);  //kein Timeout

    std::cout &lt;&lt; &quot;Event beendet&quot;&lt;&lt;std::endl;  //hier komm ich nie hin
  }
};

int main()
{

  pEvent.reset( new TEvent( NULL,  //Standard-Sicherheitsattribute0
                            true,  //manuelles Reset
                            false, //signal beim Start nicht gesetzt
                            &quot;&quot;));

  std::auto_ptr&lt; Foo&gt; pFoo( new Foo);

  MessageBox( NULL,&quot;Warten&quot;,&quot;Warten&quot;, MB_OK);

  pEvent.reset( NULL);   //TEvent-Objekt wird zerstört -&gt; es müsste in Execute-Funktion weitergehen!

  Sleep( 10000);

  return 0;
}
</code></pre>
<p>Lt. Hilfe zu TEvent::WaitFor kehrt es mit 'wrAbandoned' wenn das &quot;Ereignisobjekt [...] gelöscht [wurde], bevor das Timeout-Intervall verstrichten ist&quot;</p>
<p>in der Zeile 'pEvent.reset( NULL);' lösche ich das Ereignis-Objekt, trotzdem komm ich nie über das WaitFor hinaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850195</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Thu, 11 Aug 2005 14:28:19 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 14:05:23 GMT]]></title><description><![CDATA[<p>zu Kartoffelsack, bei uns heist das Erschtepfel ergo heißt es auch Erschtepfelsacckk.</p>
<p>mfg<br />
Tom</p>
<p>PS: nicht böse sein!!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/850196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850196</guid><dc:creator><![CDATA[Tom7]]></dc:creator><pubDate>Thu, 11 Aug 2005 14:05:23 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 14:53:56 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Müßtest du den Event mit SetEvent nicht erst auslösen damit WaitFor reagieren kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850246</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850246</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 11 Aug 2005 14:53:56 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 15:05:41 GMT]]></title><description><![CDATA[<p>Ich habs mal ausprobiert.</p>
<p>wenn du in deinem Thread vor dem WaitFor</p>
<pre><code class="language-cpp">pEvent-&gt;ResetEvent();
</code></pre>
<p>und im Hauptprogramm nach der MessageBox</p>
<pre><code class="language-cpp">pEvent-&gt;SetEvent();
</code></pre>
<p>schreibst geht das wie gewünscht.<br />
PS:<br />
Das pEvent.reset( NULL); solltest du rausschmeißen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850256</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 11 Aug 2005 15:05:41 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 15:09:21 GMT]]></title><description><![CDATA[<p>Es geht mir nicht darum, dass ich das Event auslöse. Das funzt. Es geht darum, dass ich das ganze Abbrechen möchte, ohne dass das Event eingetreten ist.<br />
Und ich möchte auch nicht mit Timeout arbeiten. Lt. Hilfe müsste das ja auch irgendwie funzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850262</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850262</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Thu, 11 Aug 2005 15:09:21 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 15:11:40 GMT]]></title><description><![CDATA[<p>Da WaitFor auf den Event wartet, wird dir wohl nichts übrigbleiben als ihn auszulösen. Wenn das automatisch gehen soll, kapsle den Event doch in eine Klasse und löse in deren Destruktor SetEvent aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850266</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 11 Aug 2005 15:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 15:29:25 GMT]]></title><description><![CDATA[<p>Das hier funktioniert bei mir</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;syncobjs.hpp&quot;
#include &lt;memory&gt;
#include &lt;iostream&gt;

class EventWrapper
{
   public:
   std::auto_ptr&lt; TEvent&gt; pEvent;
   EventWrapper()
   {
      pEvent.reset( new TEvent( NULL,  //Standard-Sicherheitsattribute0
                            true,  //manuelles Reset
                            false, //signal beim Start nicht gesetzt
                            &quot;&quot;));
   }
   ~EventWrapper()
   {
      pEvent-&gt;SetEvent();
      pEvent.reset(NULL);
   }
};

std::auto_ptr&lt;EventWrapper&gt; event;

class Foo
:public TThread
{
public:
  Foo()
  :TThread( false)
  {
  }

  virtual void __fastcall Execute(void)
  {
    event-&gt;pEvent-&gt;ResetEvent();
    event-&gt;pEvent-&gt;WaitFor( INFINITE);  //kein Timeout

    std::cout &lt;&lt; &quot;Event beendet&quot;&lt;&lt;std::endl;  //hier komm ich nie hin
  }
};

int main()
{

    event.reset( new EventWrapper);
    std::auto_ptr&lt; Foo&gt; pFoo( new Foo);

    MessageBox( NULL,&quot;Warten&quot;,&quot;Warten&quot;, MB_OK);
    event.reset( NULL);

  return 0;
}
//---------------------------------------------------------------------------
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/850279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850279</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 11 Aug 2005 15:29:25 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 16:56:44 GMT]]></title><description><![CDATA[<blockquote>
<p>Da WaitFor auf den Event wartet, wird dir wohl nichts übrigbleiben als ihn auszulösen. Wenn das automatisch gehen soll, kapsle den Event doch in eine Klasse und löse in deren Destruktor SetEvent aus.</p>
</blockquote>
<p>Wenn das Event ausgelöst wird, nur wenn ich es abbrechen will, ist es aber doof, weil es wird ja nicht wirklich ausgelöst sondern ich möchte nur nicht weiter warten und es soll NICHT der Code ausgeführt werden, der ausgeführt werden würde, wenn das Event aufgetreten wäre.</p>
<p>Ok, ich kanns dann auch mit nem Timeout und nem Ausschaltflag lösen. Aber was meint denn dann die Doku, wann der Rückgabewert wrAbandoned ausgegeben wird?</p>
<blockquote>
<p>WaitFor waits for a specified time period for the signal to be set, and returns one of the values from the following table:</p>
<p>Value Meaning<br />
wrSignaled The signal of the event was set.<br />
wrTimeout The specified time elapsed without the signal being set.<br />
wrAbandoned The event object was destroyed before the timeout period elapsed.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/850328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850328</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Thu, 11 Aug 2005 16:56:44 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 17:08:47 GMT]]></title><description><![CDATA[<blockquote>
<p>WAIT_ABANDONED<br />
0x00000080L The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/850336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850336</guid><dc:creator><![CDATA[sdk-hilfe]]></dc:creator><pubDate>Thu, 11 Aug 2005 17:08:47 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Thu, 11 Aug 2005 17:24:31 GMT]]></title><description><![CDATA[<p>Ist es richtig, wenn ich das so verstehe:</p>
<p>Wenn der Thread, der das Mutex-Objekt erstellt hat (in diesem Fall der Hauptthread, der das TEvent-Objekt erstellt hat) beendet wird, ohne das Objekt freizugeben, dann wird das den wartenden Threads damit signalisiert.</p>
<p>Korrekt?<br />
Dann ist die Borland-Hilfe aber wohl falsch, oder?</p>
<p>Schade, es ist doch eigentlich kein ungewöhnlicher Anwendungsfall, dass man das Warten auch abbrechen möchte, wenn das Ereignis nicht passiert. In meinem Fall: das Programm beenden. Könnte ich eigentlich in einem Thread auf mehrere Ereignisse warten? Dann könnt ich ein 'TuWas' und ein 'HörAuf'-Ereignis haben. Oder dem Ereignis direkt nen Parameter mitgeben (anstatt ein globales Flag, auf das von mehreren Threads zugegriffen wird).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850343</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Thu, 11 Aug 2005 17:24:31 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Fri, 12 Aug 2005 05:15:52 GMT]]></title><description><![CDATA[<p>kartoffelsack schrieb:</p>
<blockquote>
<p>Und ich möchte auch nicht mit Timeout arbeiten.</p>
</blockquote>
<p>Wieso?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850508</guid><dc:creator><![CDATA[junix]]></dc:creator><pubDate>Fri, 12 Aug 2005 05:15:52 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Mon, 15 Aug 2005 13:57:20 GMT]]></title><description><![CDATA[<p>weil eine Zeile wie</p>
<pre><code class="language-cpp">while( wrSignaled == pEvent-&gt;WaitFor( INFINITE))
{
  //doTask
}
//Abbruchcode
</code></pre>
<p>einfacher ist als mehrer Zeilen wie</p>
<pre><code class="language-cpp">while( true)
{
  int signal = pEvent-&gt;WaitFor( 1000);
  if( wrSignaled = signal)
  {
    //doTask
  }
  else
  {
    break;
  }
}
//Abbruch-Code
</code></pre>
<p>und bei Version zwei der Abbruchcode immer erst nach einer Sekunde, im Schnitt also nach 500 ms erreicht wird.</p>
<p>Das natürlich nur unter der Voraussetzung, dass das Ding so gearbeitet hätte, wie ichs mir gedacht bzw. ich es aus der Doku verstanden hätte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852564</guid><dc:creator><![CDATA[kartoffelsack@home]]></dc:creator><pubDate>Mon, 15 Aug 2005 13:57:20 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Tue, 16 Aug 2005 12:02:52 GMT]]></title><description><![CDATA[<p>Sorry für die Formatierung. Kommt davon, wenn man sich nicht einlogged.</p>
<p>Hier nochmal:</p>
<pre><code class="language-cpp">while( wrSignaled == pEvent-&gt;WaitFor( INFINITE)) 
{ 
//doTask 
} 
//Abbruchcode
</code></pre>
<p>versus</p>
<pre><code class="language-cpp">while( true) 
{ 
  int signal = pEvent-&gt;WaitFor( 1000); 
  if( wrSignaled == signal) 
  { 
  //doTask 
  } 
  else 
  { 
    break; 
  } 
} 
//Abbruch-Code
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/852566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852566</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:02:52 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Mon, 15 Aug 2005 13:59:34 GMT]]></title><description><![CDATA[<p>Ich hab das immer so gelöst, das ich &quot;Abbruch&quot;-Events in eine Liste mit den restlichen zu erwartenden Events gesetzt habe. So konnte ich unmittelbar abbrechen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852594</guid><dc:creator><![CDATA[junix]]></dc:creator><pubDate>Mon, 15 Aug 2005 13:59:34 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Tue, 16 Aug 2005 12:01:41 GMT]]></title><description><![CDATA[<blockquote>
<p>eine Liste mit den restlichen zu erwartenden Events</p>
</blockquote>
<p>Das führt mich zu meiner obigen Frage zurück:</p>
<p>kann ich auf mehrere Ereignisse zugleich warten?</p>
<p>So irgendwie ...</p>
<pre><code class="language-cpp">while(    wrSignaled == pEvent1-&gt;WaitFor( INFINITE)
       || wrSignaled == pEvent2-&gt;WaitFor( INFINITE))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/853304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853304</guid><dc:creator><![CDATA[kartoffelsack]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:01:41 GMT</pubDate></item><item><title><![CDATA[Reply to TEvent: WaitFor abbrechen on Sat, 20 Aug 2005 09:16:35 GMT]]></title><description><![CDATA[<p>Der vollständigkeit halber:</p>
<p>Auf mehrere Events warten geht nur mit WinAPI: MsgWaitForMultipleObjects</p>
]]></description><link>https://www.c-plusplus.net/forum/post/854790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/854790</guid><dc:creator><![CDATA[kartoffelsack@home]]></dc:creator><pubDate>Sat, 20 Aug 2005 09:16:35 GMT</pubDate></item></channel></rss>