Ok after a lot of research and trouble i got it working. First i have to thank SLaks for his comment. I used async/await + GetResponseAsync and it was working flawless:
public async void LoadPicture(string url)
{
bool worker = await GetURLContentsAsync(url);
}
private async Task<bool> GetURLContentsAsync(string url)
{
var webReq = (HttpWebRequest)WebRequest.Create(url);
using (WebResponse response = await webReq.GetResponseAsync())
{
.
.
.
Unfortunately GetResponseAsync is only aviable in .NET Framework 4.5 so i tried a different approach with BeginGetResponse from here: https://www.informit.com/guides/content.aspx?g=dotnet&seqNum=583 But it was either blocking the UI-thread (not asynchronous) or failed to load the picture 3/4 times (same image).
So i ended up using threads again:
private void LoadPicture(string url)
{
threadworker = new Thread(() => pictureBox1.Image = getImgFromUrl(url));
threadworker.Start();
}
public Bitmap getImgFromUrl(string url)
{
Bitmap bmp = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
try
{
bmp = new Bitmap(response.GetResponseStream());
.
.
.
As you can see it is almost the same code as in the question-post, i figured out that threadworker.IsAlive was the culprit and pictureBox1.Load() takes a lot longer than writing the stream into a temporary BitMap-file and loading it afterwards.