Cannot evaluate expression because a native frame is on top of the call stack.
Hey igen guys! Så er jeg på igen.. Denne gang får jeg fejlenCannot evaluate expression because a native frame is on top of the call stack.
Jeg har lavet en background worker i mit program, og den udfører lige præcis hvad den skal, men når den er færdig med hvad den skal, så crasher programmet lidt efter med fejlen
"Cannot evaluate expression because a native frame is on top of the call stack."
Jeg tror det er min background worker som bliver ved med at loope, men kan ikke finde fejlen . :)
Og benytter mig af kommandoen - System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
for at snyde mig fra fejlen
Cross-thread operation not valid: Control '<ting her>' accessed from a thread other than the thread it was created on.
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
int antal = 0;
backgroundWorker.WorkerSupportsCancellation = true;
if (this.backgroundWorker.CancellationPending)
{
e.Cancel = true;
return;
}
List<string> md5list;
string path = folderBrowse.SelectedPath;
if (this.InsertButton.Enabled == true)
{
Dispose();
}
if (!Directory.Exists(path))
{
MessageBox.Show("You must choose a valid path first");
}
if (choosext.Text == "Choose extention")
{
MessageBox.Show("Please Choose an extention");
}
else
{
string[] filePaths = Directory.GetFiles(path, choosext.Text,
SearchOption.AllDirectories);
md5list = new List<string>();
foreach (string file in filePaths)
{
filename = System.IO.Path.GetFileName(file);
filedir = System.IO.Directory.GetCurrentDirectory();
md5string = MD5HashFromFile(file);
if (md5list.Contains(md5string))
{
DupGrid.Rows.Add(filename, file, md5string);
}
if (md5list.Contains(md5string) == false)
{
WriteToDoc();
OrgGrid.Rows.Add(filename, file, md5string);
md5list.Add(md5string);
}
label6.Text = Convert.ToString(antal++);
if (this.backgroundWorker.IsBusy)
{
label4.Text = "Busy";
}
if (this.backgroundWorker.IsBusy == false)
{
label4.Text = "Not Busy";
}
//Here is where we use this method to pass back
//information to the UI Thread. Notice how we
//pass the current progress (limited from 0 to 100)
//as well as the actual customer object.
this.backgroundWorker.WorkerReportsProgress = false;
//this.backgroundWorker.ReportProgress(returnedRecordCount, filePaths);
System.Threading.Thread.Sleep(20);
}
}
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.ProgressPercentage <= this.progressBar1.Maximum)
{
this.progressBar1.Value = e.ProgressPercentage;
}
}
public void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.InsertButton.Enabled = true;
this.label1.Text = "Process Complete!";
}