public void serialcek()
{
while (!exitThread)
{
foreach (ManagementObject currentObject in theSearcher.Get())
{
try
{
textBox1.Text = currentObject["Size"].ToString() + " " + currentObject["PNPDeviceID"].ToString();
currentObject.Dispose();
}
catch (Exception)
{
// MessageBox.Show("Bişiler oldu bende anlamadım");
currentObject.Dispose();
//exitThread = false;
}
}
}
Thread.Sleep(100);
serialcek();
}
i use thread. but its a few minute later an error. click button is exitThread make true. than 5 min later give an StackOverflowException was unhandled HResult=-2147023895 error.
thanks for help.
Your calling
serialcek()
recursivly without stopping and by that causing a stack overflow.P.s. use finally with
try\catch
to prevent code duplication: