קצת שיפצתי את הקוד שלי על פי הקוד של דוד:
- בקריאת ה XML
- בדיקה על פי תאריך אחרון
- הרווחנו בקוד הזה שגם אם תוכנת נתיב סגורה זה לא מפריע לקרא את ה RSS
שימו לב!
יש להגדיר את ה Interval של הטיימר ל 60 שניות לפחות.
Private ns As XNamespace = "http://www.w3.org/2005/Atom"
Private lastDate As Date = Date.MinValue
Private xmlDoc As XDocument
Private href As String
Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
Try
Dim DownloadThread = New Threading.Thread(Sub()
Try
xmlDoc = XDocument.Load("http://code.613m.org/feed.php")
Catch ex As Exception
End Try
End Sub)
DownloadThread.Start()
'מנסה להוריד נתונים עד 10 שניות
For I = 0 To 10
Threading.Thread.Sleep(1000)
If DownloadThread.IsAlive = False Then
Exit For
End If
Next
'יוצא אם עד אחר 10 שניות לא הצלח להוריד
If DownloadThread.IsAlive Then
DownloadThread.Abort()
Exit Sub
End If
Dim XEl As XElement = xmlDoc.Element(ns + "feed").Elements(ns + "entry")(0)
If Date.Parse(XEl.Element(ns + "published").Value) > lastDate Then
lastDate = Now
Dim sb As New StringBuilder
sb.AppendLine("המחבר: " & XEl.Element(ns + "author").Value)
sb.AppendLine("נושא: " & XEl.Element(ns + "title").Value)
sb.AppendLine("תוכן ההודעה: " & XEl.Element(ns + "content").Value)
href = XEl.Element(ns + "link").Attributes("href")(0).Value
sb.AppendLine("לחץ כאן למעבר להודעה החדשה")
NotifyIcon1.ShowBalloonTip(5555, "הודעה חדשה בפורום", sb.ToString, ToolTipIcon.Info)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation +
MsgBoxStyle.MsgBoxRight +
MsgBoxStyle.MsgBoxRtlReading)
End Try
End Sub
Private Sub NotifyIcon1_BalloonTipClicked(sender As Object,
e As System.EventArgs) Handles NotifyIcon1.BalloonTipClicked
Try
Process.Start(href)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation +
MsgBoxStyle.MsgBoxRight +
MsgBoxStyle.MsgBoxRtlReading)
End Try
End Sub
פורסם במקור בפורום CODE613 ב14/02/2014 13:40 (+02:00)

