(v2)DownloadFileAsync - Attempted to read or write protected memo
Hej Eksperter.(Framework v2)
Jeg har en lille download application, hvor jeg har valgt at bruge downloadfileasync(uri, string); da jeg kan koble en event på, men den kommer med denne underlige fejl: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." og har søgt på nettet. Kan ikke finde noget, som kan løse mit problem..
Så tænkte i måske kunne :)
Lidt kode:
class MegaUpload
{
private WebClient client;
private MGUD.MainForm mf;
private Uri uri;
public int row;
public string url;
public string OutputFilename = "";
public string OutputDirectory = "";
public MegaUpload(MGUD.MainForm mf)
{
this.mf = mf;
this.client = new WebClient();
this.client.DownloadFileCompleted += this.client_DownloadFileCompleted;
this.client.DownloadProgressChanged += this.client_DownloadProgressChanged;
}
public void StartRequest()
{
try
{
string output = this.OutputDirectory + @"\" + this.OutputFilename;
this.uri = new Uri(this.url);
mf.SetStatus(this.row, "Try Downloading");
client.DownloadFileAsync(this.uri, this.OutputFilename);
}
catch (UriFormatException ex)
{
mf.SetStatus(this.row, ex.Message);
MessageBox.Show(ex.Message);
}
}
private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error == null)
MessageBox.Show("Download Complete");
else
MessageBox.Show("Download Not Complete: " + e.Error.Message);
}
// Updates the progress indicator with the latest progress
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
mf.glacialList1.Items[this.row].SubItems[0].Text = "Downloading..";
ProgressBar pb = new ProgressBar();
pb.Value = e.ProgressPercentage;
mf.glacialList1.Items[this.row].SubItems[2].Control = pb;
}
}
Variabler som bliver sat før StarRequest bliver kaldt.
public int row;
public string url;
public string OutputFilename = "";
public string OutputDirectory = "";
