Make a timer async and thread safe
Hi everybody, I want to make an async timer but I'm straggling a bit with thread safe.. I m not able not to call object from main thread. The code is this one:
Code:
Dim res As String
Dim client As New WebClient()
client.Encoding = Encoding.UTF8
client.Headers.Add(HttpRequestHeader.UserAgent, "")
Dim stream = client.OpenRead("url link")
Dim sr As StreamReader = New StreamReader(stream)
BetterListBox1.Items.Clear()
res = (sr.ReadToEnd)
'FILTRO I TAG HTML DAL CONTENUTO RAW
' Dim sourcestring As String = res
Dim matchpattern As String = "<(?:[^>=]|='[^']*'|=""[^""]*""|=[^'""][^\s>]*)*>"
Dim replacementstring As String = ""
res = ((Regex.Replace(res, matchpattern, "")))
res = WebUtility.HtmlDecode(res)
Dim visibleItems As Integer = CInt(BetterListBox1.ClientSize.Height / BetterListBox1.ItemHeight)
BetterListBox1.Items.AddRange(Split(res, vbLf))
BetterListBox1.TopIndex = Math.Max(BetterListBox1.Items.Count - visibleItems + 1, 0)
End Sub
There is a way where I can make this code run async? Thanks
Re: Make a timer async and thread safe
What Timer? I commented on this question on SO and the it's just as inadequate a description here as it is there.
Also, what would make you think that posting code with all that leading whitespace was a good idea? Please make an effort to help us help you by posting as clearly as possible. You can hold down the Alt key while selecting an arbitrary block of text in VS so there's no reason to ever post code with pointless whitespace.
As for the threading issue, follow the CodeBank link in my signature below and check out my thread on Accessing Controls From Worker Threads.