עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

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#

Featured Replies

פורסם

שלום

יש לי את הקוד הבא

for (int k = 0; k < 10; k++)
{
if (array_1[k] == 1)
{
timer2.Tick += new System.EventHandler(this.timer2_Tick);
button1.BackColor = Color.Blue;

}

if (array_1[k] == 2)
{
timer2.Tick += new System.EventHandler(this.timer2_Tick);
button2.BackColor = Color.Green;


}

if (array_1[k] == 3)
{
timer2.Tick += new System.EventHandler(this.timer2_Tick);
button3.BackColor = Color.Yellow;

}

if (array_1[k] == 4)
{
timer2.Tick += new System.EventHandler(this.timer2_Tick);
button4.BackColor = Color.Red;

}

}

ניסיתי לעשות עם טיימר שבין סיבוב לסיבוב בלולאה (בסה''כ יש 10 סיבובים) שהוא יחכה מספר שניות (כ-3) ואני לא מצליח,הוא ממשיך בלולאה ועושה הכל רצוף וזה לא טוב .

מה צריך להוסיף כדי שהוא יחכה בין סיבוב לסיבוב?

תודה מראש

פורסם

השורה הזו:

timer2.Tick += new System.EventHandler(this.timer2_Tick);

לא גורמת לתוכנית לחכות, היא רק רושמת את הפונקציה לטיימר, וממשיכה.

בשביל מה שאתה רוצה לעשות, צריך אחד משני דברים - להשתמש בפונקציית sleep, או לדאוג שמה שאתה רוצה שיקרה כל 3 שניות יקרה בתוך הפונקציה timer2_tick (ואז בתוך הפונקציה תצטרך לזכור כמה פעמים קראו לה, ולהתייחס בתוכה לערכים שבמערך).

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

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.