WebClient Throws "No Data Available for Encoding 1252" - c#

Im making a program, which is working nicely, except i started to create an update system and somehow its not working. The splash screen checks for updates, using a webClient, which now seems to error as well. I set it up so the splash screen downloads a text file. If the versions mismatch, a separate form starts and uses a webClient to download the updater. I've created this form twice. It has 1 progressBar, 1 webClient, an image background and 1 label. The update is supposed to download, show its progress on the bar, and then open the updater and close the main program. The first time i created the form, i ran it and it would freeze and not download the file. After i stopped debugging, the design window of visual c# express 2010 would crash and I had to restart vc#. The window would show all of the items i had added except the webClient. So i tried debugging again and i got this message:
Error 1 Invalid Resx file. Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip
Error 2 TargetInvocationException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252.
at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader)
at System.Resources.ResXResourceReader.EnsureResData()
at System.Resources.ResXResourceReader.GetEnumerator()
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(ReaderInfo readerInfo, IResourceReader reader, String fileName)
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(String filename, Boolean shouldUseSourcePath)
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFileOrDir)
XmlException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. Line 138, position 5.
NotSupportedException: No data is available for encoding 1252.
at System.Text.BaseCodePageEncoding.LoadCodePageTables()
at System.Text.BaseCodePageEncoding..ctor(Int32 codepage, Int32 dataCodePage)
at System.Text.SBCSCodePageEncoding..ctor(SerializationInfo info, StreamingContext context)
C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip
So i deleted the webClient from the form and retried. I got the same error a second time. So i googled the first error, and found one response on hackforums with no fixes. And now im entirely lost. All my webClients seem to be doing this now and i have no idea why.
Here's the code from my splash screen:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace TubeRip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
getupdates();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer2.Start();
}
private void timer2_Tick_1(object sender, EventArgs e)
{
timer1.Stop();
label1.Text = "Loading Core Components..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 20)
{
progressBar1.Value += 1;
}
else
{
timer3.Start();
}
}
private void end()
{
timer7.Stop();
mainpage home = new mainpage();
home.Show();
this.Dispose(false);
}
private void timer3_Tick(object sender, EventArgs e)
{
timer2.Stop();
label1.Text = "Loading Encryption Algorithyms..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 40)
{
progressBar1.Value += 1;
}
else
{
timer4.Start();
}
}
private void timer4_Tick(object sender, EventArgs e)
{
timer3.Stop();
label1.Text = "Enabling Download Services..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 60)
{
progressBar1.Value += 1;
}
else
{
timer5.Start();
}
}
private void timer5_Tick(object sender, EventArgs e)
{
timer4.Stop();
label1.Text = "Disabling Youtube's Download Protection..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 80)
{
progressBar1.Value += 1;
}
else
{
timer6.Start();
}
}
private void timer6_Tick(object sender, EventArgs e)
{
timer5.Stop();
label1.Text = "Drawing GUI" + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 90)
{
progressBar1.Value += 1;
}
else
{
timer7.Start();
}
}
private void timer7_Tick(object sender, EventArgs e)
{
timer6.Stop();
label1.Text = "Creating The first Humanlike Robot..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 100)
{
progressBar1.Value += 1;
}
else
{
end();
}
}
private void getupdates()
{
try
{
string updateurl = "http://dl.dropbox.com/u/22054429/TubeRip_version.txt";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateurl);
WebResponse response = request.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("windows-1252"));
string update = sr.ReadToEnd();
int build = Convert.ToInt32(update);
int thisbuild = 2;
if (build > thisbuild)
{
label2.Visible = true;
TubeRip.Properties.Settings.Default.UpdateAvail = true;
}
else
{
label2.Visible = false;
TubeRip.Properties.Settings.Default.UpdateAvail = false;
}
}
catch
{
MessageBox.Show("Unable to connect to update server! Please try again later.");
}
}
}
}
And here's the code from my updater:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
namespace TubeRip
{
public partial class updates : Form
{
public updates()
{
InitializeComponent();
}
private void updates_Load(object sender, EventArgs e)
{
Uri update = new Uri("http://dl.dropbox.com/u/22054429/TubeRip_Installer.exe");
webClient1.DownloadFileAsync(update, "update.exe");
webClient1.DownloadProgressChanged +=new DownloadProgressChangedEventHandler( webClient1_DownloadProgressChanged);
webClient1.DownloadFileCompleted += new AsyncCompletedEventHandler( webClient1_DownloadFileCompleted);
}
void webClient1_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Process.Start("update.exe");
Environment.Exit(0);
}
void webClient1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
label1.Text = "Downloading Updates Please Wait... " + e.ProgressPercentage.ToString() + "%";
}
}
}

I did not find any result to my specific error, but i did find a way to work around it. Instead of using the default encoding for a webClient, i set the encoding myself to UTF-8, which does not throw this error. The modified code is what ended up working.
WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
Uri update = new Uri(uri);
client.DownloadFileAsync(update, "update.exe");
client.DownloadProgressChanged +=new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
Otherwise, i have found no fix to this issue, and no reason for this issue to appear.

Related

How to make a customized progressbar in c#

I would like to learn how to make a progressbar like the one shown in this video.
I tried to replicate it in VS C#, but I get the error:
C# Property or indexer cannot be assigned to -- it is read only
If I try using if (txProgressBar.Text.Length == 85), I will get this in the TextBox (txProgressBar)
System.Windows.Forms.TextBox, Text: System.Windows.Forms.TextBox, Text: Syst...██
Textbox Progressbar Tutorial VB 2010
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomizedProgressBar
{
public partial class Form1 : Form
{
int last = 1;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (txProgressBar.Text.Length = "85")
{
timer1.Stop();
MessageBox.Show("Counted!");
}else
{
if (last == 1)
{
txProgressBar.Text = txProgressBar + "█";
last = 2;
}
else
{
txProgressBar.Text = txProgressBar.Text + "█";
last = 1;
}
}
}
private void btnClear_Click(object sender, EventArgs e)
{
txProgressBar.Text = "";
}
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
Your line:
txProgressBar.Text = txProgressBar + "█";
should be
txProgressBar.Text = txProgressBar.Text + "█"; or txProgressBar.Text &= "█";
I realized what was the problem. The txProgressBar.Text = txProgressBar + "█"; was missing the *.Text. That solved the problem and the message is shown as well.

I'm trying to use backgroundworker with webBrowser to download images but getting exception. What should i do?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using HtmlAgilityPack;
using mshtml;
using System.Text.RegularExpressions;
namespace Extract_Images
{
public partial class Form1 : Form
{
private string[] linkstoextract;
private int numberoflinks;
private int currentLinkNumber = 0;
private string mainlink;
private WebClient client;
private WebBrowser webBrowser1;
private string htmlCode;
private bool pagesorimages = false;
public Form1()
{
InitializeComponent();
webBrowser1 = new WebBrowser();
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
label1.Text = "Number of links: ";
mainlink = "http://www.test.com/";
numberoflinks = 13;
backgroundWorker1.RunWorkerAsync();
}
private void ProcessNextLink()
{
if (currentLinkNumber < numberoflinks)
{
currentLinkNumber++;
string linktonav = mainlink + "index"+currentLinkNumber.ToString() + ".html";
pagesorimages = false;
backgroundWorker1.ReportProgress(0,currentLinkNumber);
webBrowser1.Navigate(linktonav);
}
}
int count = 0;
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
mshtml.HTMLDocument objHtmlDoc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
string pageSource = objHtmlDoc.documentElement.innerHTML;
List<string> links = new List<string>();
string[] hrefs = this.webBrowser1.Document.Links.Cast<HtmlElement>()
.Select(a => a.GetAttribute("href")).Where(h => h.Contains(".jpg")).ToArray();
foreach(string a in hrefs)
{
using (WebClient client = new WebClient())
{
client.DownloadFile(a, #"C:\Images\file" + count + ".jpg");
}
count ++;
pagesorimages = true;
backgroundWorker1.ReportProgress(0, count);
}
//ProcessNextLink();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ProcessNextLink();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (pagesorimages == false)
{
label1.Text = e.UserState.ToString();
}
if (pagesorimages == true)
{
label2.Text = e.UserState.ToString();
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
}
}
The exception is on the second ReportProgress:
backgroundWorker1.ReportProgress(0, count);
This operation has already had OperationCompleted called on it and further calls are illegal
What i want to do is to report first the current page number in this case it's 1 to label1.
And then to report the number of downloaded images in this page to label2.
Then to move to the next page with the method ProcessNextLink(); and again report the page number it should be 2 and then to report the number of images downloaded in page 2.
But i'm getting this exception already on the first page.
It was working fine without the backgroundworker in the event webBrowser1_DocumentCompleted i called ProcessNextLink(); in the bottom and it was working fine. But with the backgroundworker it's not working.

Winsock with C# Severity Code ERROR: The name 'DataInput' does not exist in the current context

I'm new to coding in c#,My Project is connecting server and client using Winsock control. I am doing exactly this program http://www.go4expert.com/articles/winsock-c-sharp-t3312/ to connect server and client.
form:
enter image description here
code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Winsock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.w1.Error += new AxMSWinsockLib.DMSWinsockControlEvents_ErrorEventHandler(this.w1_Error);
this.w1.ConnectEvent += new System.EventHandler(this.w1_ConnectEvent);
this.w1.DataArrival += new AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEventHandler(this.w1_DataArrival);
}
Boolean isConnect = false;
private void w1_ConnectEvent(object sender, EventArgs e)
{
DataInput.Text += "\n - Connect Event : " + w1.RemoteHostIP;
isConnect = true;
}
public void w1_Error(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent e)
{
DataInput.Text += "\n- Error : " + e.description;
isConnect = false;
}
private void w1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
{
String data = "";
Object dat = (object)data;
w1.GetData(ref dat);
data = (String)dat;
DataInput.Text += "\nServer - " + w1.RemoteHostIP + " : " + data;
}
private void send_Click(object sender, EventArgs e)
{
try
{
if (isConnect)
{
w1.SendData(SendText.Text);
DataInput.Text += "\nClent(You ;-) : " + SendText.Text;
SendText.Text = "";
}
else
MessageBox.Show("You are not connect to any host ");
}
catch (AxMSWinsockLib.AxWinsock.InvalidActiveXStateException g)
{
DataInput.Text += "\n" + g.ToString();
}
catch (Exception ex)
{
DataInput.Text += "\n" + ex.Message;
}
}
private void disconnect_Click(object sender, EventArgs e)
{
w1.Close();
w1.LocalPort = Int32.Parse(portText.Text);
w1.Listen();
DataInput.Text += "\n - Disconnected";
}
private void Connect_Click(object sender, EventArgs e)
{
try
{
w1.Close();
w1.Connect(IPText.Text, portText.Text);
}
catch (System.Windows.Forms.AxHost.InvalidActiveXStateException g)
{
DataInput.Text += "\n" + g.ToString();
}
}
private void w1_ConnectionRequest(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent e)
{
if (isConnect == true)
{
w1.Close();
}
w1.Accept(e.requestID);
isConnect = true;
DataInput.Text += "\n - Client Connected :" + w1.RemoteHostIP;
}
}
}
Error
The name 'DataInput' does not exist in the current context
I can't seem to find a solution to this problem by searching the web Please help me :(
Create a Textbox Named "DataInput" on your form.

How to plot graphs with data from a SerialPort with multiple sensors

I need to plot data from sensors of pH, Temperature and Humidity, the data is sent as a matrix from arduino to PC through the serial port.
I can show the data in a TextBox, but when I try to plot the data, it doesn't work (I don't know how to do it).
I just can plot the data when is not a matrix and it's data from just one sensor.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Windows.Forms.DataVisualization.Charting;
namespace grafik1
{
public partial class Form1 : Form
{
private SerialPort sensport;
private DateTime datetime;
private string data;
private string data2;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = SerialPort.GetPortNames();
timer1.Start();
}
double rt = 0;
Boolean i = false;
private void timer1_Tick(object sender, EventArgs e)
{
rt = rt + 0.1;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
sensport.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox2.Text == "")
{
MessageBox.Show("Error");
}
else
{
sensport = new SerialPort();
sensport.BaudRate = int.Parse(comboBox2.Text);
sensport.PortName = comboBox1.Text;
sensport.Parity = Parity.None;
sensport.DataBits = 8;
sensport.StopBits = StopBits.One;
sensport.Handshake = Handshake.None;
sensport.DataReceived += sensport_DataReceived;
try
{
sensport.Open();
textBox1.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
}
void sensport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (i == false)
{
rt = 0;
i = true;
}
data = sensport.ReadLine();
this.chart1.Series["Data1"].Points.AddXY(rt, data);
this.Invoke(new EventHandler(displaydata_event));
}
private void displaydata_event(object sender, EventArgs e)
{
datetime = DateTime.Now;
string time = datetime.Day + "/" + datetime.Month + "/" + datetime.Year + "\t" + datetime.Hour + ":" + datetime.Minute + ":" + datetime.Second;
txtData.AppendText(time + "\t" + data + "\n");
}
private void button2_Click(object sender, EventArgs e)
{
string directorio = textBox1.Text;
if (directorio == "")
{
MessageBox.Show("Error");
}
else {
try
{
string kayıtyeri = #"" + directorio + "";
this.chart1.SaveImage(("+kayityeri+"), ChartImageFormat.Png);
MessageBox.Show("Grafica guardada en " + kayıtyeri);
}
catch (Exception ex3)
{
MessageBox.Show(ex3.Message, "Error");
}
}
}
private void label4_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
sensport.Close();
}
private void button4_Click(object sender, EventArgs e)
{
try
{
string pathfile = #"C:\Users\MARIO GONZALEZ\Google Drive\VisualStudio\Arduino0_1\DATA";
string filename = "arduinoRTPv1.xls";
System.IO.File.WriteAllText(pathfile + filename, txtData.Text);
MessageBox.Show("Data saved");
}
catch (Exception ex3)
{
MessageBox.Show(ex3.Message, "Error");
}
}
private void button5_Click(object sender, EventArgs e)
{
}
private void chart1_Click(object sender, EventArgs e)
{
}
}
}
Let's assume you have prepared your chart, maybe like this:
chart1.Series.Clear();
chart1.Series.Add("ph");
chart1.Series.Add("Temp");
chart1.Series.Add("Hum");
chart1.Series["ph"].ChartType = SeriesChartType.Line;
chart1.Series["Temp"].ChartType = SeriesChartType.Line;
chart1.Series["Hum"].ChartType = SeriesChartType.Line;
chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
chart1.ChartAreas[0].AxisY2.Title = "Temp";
chart1.ChartAreas[0].AxisY2.Maximum = 100;
Now you can add a string that contains some data blocks as shown in the comments..
string data = "7.5 23.8 67 \n8.5 23.1 72 \n7.0 25.8 66 \n";
..like this:
var dataBlocks = data.Split('\n');
foreach (var block in dataBlocks)
{
var numbers = block.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries);
// rt += someTime; (*)
for (int i = 0; i < numbers.Length; i++)
{
double n = double.NaN;
bool ok = double.TryParse(numbers[i], out n);
if (ok) chart1.Series[i].Points.AddXY(rt, n);
else
{
int p = chart1.Series[i].Points.AddXY(rt, 0);
chart1.Series[i].Points[p].IsEmpty = true;
Console.WriteLine("some error message..");
}
}
}
I have modified the data a little to show the changes a little better..
Note that I left out the counting up of your timer rt, which is why the chart shows the points with indexed x-values. For a real realtime plot do include it maybe here (*) !
If you keep adding data your chart will soon get rather crowded.
You will then either have to remove older data from the beginning or at least set a minimum and maximum x-values to restrict the display to a reasonably number of data points and or turn on zooming!
See here here and here for some examples and discussions of these things!

Dowloading Files One at a time in C# [duplicate]

This question already has answers here:
True Parallel Downloads
(2 answers)
Closed 8 years ago.
I am trying to download one file at a time. But when I add my value2 into the await Task.Delay(value2); It still downloads both files at the same instead of one at a time. Mind you that I will be putting checkboxes to the ones that I want to download and there are going to be about 20 to 50 downloads to which I would be able to choose which to download. But the main thing is how to download one at a time instead of all at the same time.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
namespace DownloadFileCSharp8
{
public partial class Form1 : Form
{
private Stopwatch workerTimeElaspsed;
public Form1()
{
InitializeComponent();
}
private async void btnGetDownload_Click(object sender, EventArgs e)
{
string text = label5.Text;
int value2;
//value2 = value2 + 5;
int.TryParse(text, out value2);
InitiateDownload("http://stie.text1.txt", #"E:\Files\text1.txt", wc_DownloadFileCompleted, "text1.txt");
await Task.Delay(value2);
InitiateDownload("http://site.text.docx", #"E:\Files\text2.docx", wc_DownloadFileCompleted, "text2.docx");
}
void InitiateDownload(string RemoteAddress, string LocalFile, AsyncCompletedEventHandler CompleteCallBack, object userToken)
{
WebClient wc = new WebClient();
wc.DownloadProgressChanged += wc_DownloadProgressChanged;
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadTimer);
wc.DownloadFileCompleted += wc_DownloadFileCompleted;
wc.DownloadFileAsync(new Uri(RemoteAddress), LocalFile, userToken);
workerTimeElaspsed = new Stopwatch();
workerTimeElaspsed.Start();
}
private void DownloadTimer(object sender, DownloadProgressChangedEventArgs e)
{
progressBar2.Value = e.ProgressPercentage;
if (e.ProgressPercentage > 0)
{
double totalTime = (100d / (double)e.ProgressPercentage) * workerTimeElaspsed.Elapsed.TotalSeconds;
double remaining = totalTime - workerTimeElaspsed.Elapsed.TotalSeconds;
label5.Text = Math.Round(remaining).ToString();
}
}
void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
lblInfo1.Visible = true;
lblInfo1.ForeColor = Color.Red;
lblInfo1.Text = "Error Downloading ";
//throw e.Error;
}
else if (e.Cancelled)
{
lblInfo1.Visible = true;
lblInfo1.ForeColor = Color.Red;
lblInfo1.Text = "Download Cancelled " + e.UserState + e.Error;
}
else
{
lblInfo1.Visible = true;
lblInfo1.ForeColor = Color.Red;
lblInfo1.Text = e.UserState + " Download Complete!! ";
}
//throw new NotImplementedException();
}
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
}
}
You call InitiateDownload to start the download, then wait for a fixed period of time (which appears to be very short), then you call InitiateDownload again to start another download *regardless of whether or not the first download has finished.
What you want to do is re-write InitiateDownload so that it returns a Task that indicates when the download is complete. You can then await that task and start the next download when it is done.
The easiest way to do that is to simply use the DownloadDataTaskAsync method instead of DownloadFileAsync.
You need to use your DownloadFileCompleted event to trigger the next InitiateDownload if you want them to happen serially.

Categories