I have code running in background worker, which verifies if mentioned link(website) is valid. if not valid, the procedure gives error and goes on to check another link. To achieve this I m using webrequest and webresponse.
The problem starts when while background worker is accessing links, if I try to download something from main thread(which works totally fine if backgroundworker is not working), the download doesn't complete.
Code for Backgroundworker:
Try
Dim bgwebRequest As WebRequest
Dim bgwebresponse As WebResponse
bgwebRequest = WebRequest.Create(websitelink)
bgwebRequest.Timeout = 200
bgwebresponse = bgwebRequest.GetResponse()
'//code for website found
Catch ex As Exception
'//code for website not found
End Try
code for downloadingfile:
Dim download As WebClient = New WebClient
download.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64;
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84
Safari/537.36")
download.DownloadFileAsync(New Uri(directdownloadlink), downloadpathinpc)
AddHandler download.DownloadFileCompleted, AddressOf OnDownloadComplete1
download.Dispose()
code for ondownloadcomplete1:
'//run tasks that needs to completed if download is comolete
If backgroundworker is running, the debugger never reaches "ondownloadcomplete1"