Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[c#] Timer Mehrfachaufruf

Empfohlene Antworten

Veröffentlicht

Hallo,

ich habe einen Timer in einem Formular. Dieser Timer ruft zyklisch etwa so eine Methode auf:


bool bTimerRun;


OnTick()

{

 if(bTimerRun)

  return;


 bTimerRun=true;


 MessageBox.Show("Test");


 bTimerRun=false;

}


Die MessageBox wird nur einmal angezeigt und der Timer wird gleich im Keim erstickt.

Prinzipiell funktioniert das, aber kommt da evtl. der GC oder die Runtime durcheinander? Der erste Methodenaufruf wird ja nach Bestätigen der MessageBox erst beendet.

Über den Sinn obiger Methode brauchen wir nicht zu diskutieren, die ist nur als Anschauung gedacht.

Grüße

Steinadler

Hey steinadler!

So wie ich das verstehe, macht die Methode genau das, was sie soll.

Die Variable wird erst nach Schließen der MessageBox wieder auf "false" gesetzt. Dein Timer tickt wahrscheinlich fröhlich vor sich hin und springt jedes mal bei return aus der Methode, weil "bTimerRun" ja tatsächlich noch "true" ist.

Gruß, Ziege

Bearbeitet von Goulasz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.