I need that Join method is called when Download.file method have finished. I tried to add await keyword but it didn't work
Thread myThread = new Thread(new ThreadStart(()=> await Download.file(uri))); Thread myThread = new Thread(new ThreadStart(()=>Download.file(uri))); myThread.Start(); myThread.Join(); class Download{ public static async void file(string url) { try { HttpWebRequest request; HttpWebResponse webResponse = null; request = HttpWebRequest.CreateHttp(url); request.AllowReadStreamBuffering = true; webResponse = await request.GetResponseAsync() as HttpWebResponse; Stream responseStream = webResponse.GetResponseStream(); using (StreamReader reader = new StreamReader(responseStream)) { string content = await reader.ReadToEndAsync(); } webResponse.Close(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } Thanks