Thread NOT aborting nicely!!!!
-
Hey, running an app that has to enumerate thru a treeView and create a connection to each node(or pc). because our network is so large i need to give the users the ablity to close the connection/exit the application prior to the connection closing itself. The problem i'm running into is that i'm running the treeView enumeration on a separate thread (due to the time/system expense and it was continually locking up the interface) and I can't elegantly kill the thread. I intermittently receive "Thread was being aborted" when trying to stop/abort the thread. I've searched around and all i can find is related to web redirects, which isn't my problem. I've attempted to follow the msdn directives regarding this but haven't had any luck(thread.join). I've also tried to look into closing the connection as that would allow the thread to close properly, but i can't find anything on how to close a managementScope object. (I may have not looked hard enought on this part :~ ) I could use any help that you may offer. string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
-
Hey, running an app that has to enumerate thru a treeView and create a connection to each node(or pc). because our network is so large i need to give the users the ablity to close the connection/exit the application prior to the connection closing itself. The problem i'm running into is that i'm running the treeView enumeration on a separate thread (due to the time/system expense and it was continually locking up the interface) and I can't elegantly kill the thread. I intermittently receive "Thread was being aborted" when trying to stop/abort the thread. I've searched around and all i can find is related to web redirects, which isn't my problem. I've attempted to follow the msdn directives regarding this but haven't had any luck(thread.join). I've also tried to look into closing the connection as that would allow the thread to close properly, but i can't find anything on how to close a managementScope object. (I may have not looked hard enought on this part :~ ) I could use any help that you may offer. string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
wetrivrrat wrote:
The problem i'm running into is that i'm running the treeView enumeration on a separate thread (due to the time/system expense and it was continually locking up the interface) and I can't elegantly kill the thread. I intermittently receive "Thread was being aborted" when trying to stop/abort the thread.
As long as your applcation is not left in an unusable state, IMO just catching that should be ok. Another idea is to use a bool (perhaps static) value somewhere that u can set to exit the thread. You can also look at some other classes in the Threading namespace, but normally a simple check is enough. :)
-
wetrivrrat wrote:
The problem i'm running into is that i'm running the treeView enumeration on a separate thread (due to the time/system expense and it was continually locking up the interface) and I can't elegantly kill the thread. I intermittently receive "Thread was being aborted" when trying to stop/abort the thread.
As long as your applcation is not left in an unusable state, IMO just catching that should be ok. Another idea is to use a bool (perhaps static) value somewhere that u can set to exit the thread. You can also look at some other classes in the Threading namespace, but normally a simple check is enough. :)
Thanks for the response, i've included a small section of the code that deals with the thread abort calls. I guess a bit more description into what i'm receiving may help... its not so much the initial error, as i could find a creative way to handle it, but its that i'm receiving the error multiple times. So even if i catch the error i'll still have to deal with multiple instances of the same issue. After watching the system processes I can see that instead of increasing by only one thread, or maybe even two for that matter i'm actually increasing by 4 sometimes 7 while the app is enumerating thru the connection nodes... this is only a concern because i'm receiving sometimes 3 or more "Thread was being aborted" messages, so i wanted to see why. I've also tried to capture that message by using a try,catch, but haven't yet found a way to do it. not sure if that has anything to do with the unhandled exception nature of this message or not, but its just odd.... anyhow i'm sure i'm only confusing the situation more by explaining...
case 3:
result = MessageBox.Show("~","Please Verify", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
try
{
if(result == DialogResult.Yes)
{
menuItem42.Visible=true;
menuItem45.Visible=false;
if (PcTree.IsAlive == true)
{
PcTree.Abort();
PcTree.Join();
label1.ResetText();
progressBar1.Value = progressBar1.Minimum;
}
}
}
catch (ThreadAbortException abort)
{MessageBox.Show(abort.Message + abort.StackTrace);}
break;string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
-
Thanks for the response, i've included a small section of the code that deals with the thread abort calls. I guess a bit more description into what i'm receiving may help... its not so much the initial error, as i could find a creative way to handle it, but its that i'm receiving the error multiple times. So even if i catch the error i'll still have to deal with multiple instances of the same issue. After watching the system processes I can see that instead of increasing by only one thread, or maybe even two for that matter i'm actually increasing by 4 sometimes 7 while the app is enumerating thru the connection nodes... this is only a concern because i'm receiving sometimes 3 or more "Thread was being aborted" messages, so i wanted to see why. I've also tried to capture that message by using a try,catch, but haven't yet found a way to do it. not sure if that has anything to do with the unhandled exception nature of this message or not, but its just odd.... anyhow i'm sure i'm only confusing the situation more by explaining...
case 3:
result = MessageBox.Show("~","Please Verify", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
try
{
if(result == DialogResult.Yes)
{
menuItem42.Visible=true;
menuItem45.Visible=false;
if (PcTree.IsAlive == true)
{
PcTree.Abort();
PcTree.Join();
label1.ResetText();
progressBar1.Value = progressBar1.Minimum;
}
}
}
catch (ThreadAbortException abort)
{MessageBox.Show(abort.Message + abort.StackTrace);}
break;string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
okay, okay, it looks like i'm getting closer to the resolution.... it appears that either by accident( :confused: ) or by the objects design, i am actually creating at least 2 other threads at the same instance when i am starting the enumeration loop, so when i go to close it, the first actually closes nicely, its the others that are left in the loop that start #itching .... So, i'm off to see the wizard, the wonderful wizard of Threads to see what I have to do get home. Now, if i could only find my way.... :~ string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?