עבור לתוכן
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.

שימוש בTIMER ב-C#

Featured Replies

פורסם

אני צריך לעבוד עם Timer אבל יש לי בעיה שאני לא מבין מהותה.

יש לי שיטה שנמצאת במחלקה אחרת וצריכה לפעול במחלקה ראשית מתוזמנת.

קראתי בתיעוד של המחלקה TIMER אבלי ש לי שגיאה שאני כותב:

System.Threading.Timer t = new System.Threading.Timer(Database.Instance.Save, null, 50, 10000);

אני מקבל שתי שגיאות:


Error 1 The best overloaded method match for 'System.Threading.Timer.Timer(System.Threading.TimerCallback, object, int, int)' has some invalid arguments C:\Users\EFOD\Desktop\ניסיוני\פרויקט חדש\Forms\Forms\MainForm.cs 15 36 Forms
Error 2 Argument '1': cannot convert from 'method group' to 'System.Threading.TimerCallback' C:\Users\EFOD\Desktop\ניסיוני\פרויקט חדש\Forms\Forms\MainForm.cs 15 63 Forms

פורסם
  • מחבר

זאת שיטה ממחלקה אחרת שמעוצבת בסינגל טון.

המחלקה הראשית היא מריצה את כל התוכנית בנוסף מפעילה את השיטה save בסגירה שלה

כמו כן רציתי שתופעל כל 10 דק'

פורסם

ברור לך ש-Database.Instance.Save צריכה להיות delegate מסוג TimerCallback?

פורסם
  • מחבר

איך אני מגדיר אותה כ-TimerCallback?

שניצל, מה הכוונה בהגדרה שלה? היא שיטה חסרת פרמטרים שלא מחזירה ערך...

פורסם

אז הנה הבעיה שלך. TimerCallback צריכה להיות לקבל פרמטר אחד מסוג Object

http://msdn.microsoft.com/en-us/library/system.threading.timercallback.aspx

וכשאני אומר "מה ההגדרה", אני מתכוון שתעשה copy-paste לקוד שמגדיר את הפונקציה.

חוץ מזה, כדאי לך ללמוד קצת על delegates ואיך בדיוק משתמשים בזה.

פורסם
  • מחבר

בסדר הבנתי את הבעיה הגדרת ה-delegate הייתה צריכה להיות

private void TimerCallback (object state)

זה פתר את השגיאה,

ארכיון

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

דיונים חדשים

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.