Click here to Skip to main content
15,905,233 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to close all form but not application.exit() Pin
SilimSayo11-Feb-10 9:17
SilimSayo11-Feb-10 9:17 
QuestionUsing Semaphore for multiple threads.... Pin
Jacob Dixon11-Feb-10 4:45
Jacob Dixon11-Feb-10 4:45 
AnswerRe: Using Semaphore for multiple threads.... Pin
N a v a n e e t h11-Feb-10 5:22
N a v a n e e t h11-Feb-10 5:22 
GeneralRe: Using Semaphore for multiple threads.... Pin
Jacob Dixon11-Feb-10 5:37
Jacob Dixon11-Feb-10 5:37 
AnswerRe: Using Semaphore for multiple threads.... Pin
Covean11-Feb-10 5:25
Covean11-Feb-10 5:25 
GeneralRe: Using Semaphore for multiple threads.... Pin
Jacob Dixon11-Feb-10 5:40
Jacob Dixon11-Feb-10 5:40 
GeneralRe: Using Semaphore for multiple threads.... Pin
Jacob Dixon11-Feb-10 5:42
Jacob Dixon11-Feb-10 5:42 
GeneralRe: Using Semaphore for multiple threads.... Pin
Covean12-Feb-10 0:13
Covean12-Feb-10 0:13 
I never worked with remote WMI so I never ran in this problem.

So back to the topic.
I think in your case you can abort your threads.

But I think it would be a better solution, to tell the thread (you want to abort) that it should exit immediately after it finished its query and leave it alone/let it run till its exits (maybe you should add a kind of observer to abort threads, that didn't finish in a determined timeout).

So you couldn't use your semaphore any more (because of the possibility, that more than 3 threads are running) but it would be better to let the thread make a clean exit.

Why I think this is a better solution?
WMI calls are made through some unmanaged (not sure) COM interfaces.
Now if you abort your thread, there maybe will be some resources that would be still locked and never
gets freed till the application exits.


On the other hand you could also try to do some clean up in your thread if it gets aborted.
Something like this:

public void ThreadFunc(object obj)
{
   try
   {
       DoSomeOperation();
   }
   catch(ThreadAbortException ex)
   {
       // gets called if you abort your
       // thread and after finally
       DoAbortCleanupStuff();
   }
   finally
   {
       // general cleanup stuff
   }
}


I hope that helps.
Greetings
Covean

QuestionCreating a live service in c# Pin
Steve-Co11-Feb-10 4:29
Steve-Co11-Feb-10 4:29 
AnswerRe: Creating a live service in c# Pin
#realJSOP11-Feb-10 6:03
professional#realJSOP11-Feb-10 6:03 
GeneralRe: Creating a live service in c# Pin
Steve-Co11-Feb-10 23:32
Steve-Co11-Feb-10 23:32 
GeneralRe: Creating a live service in c# Pin
#realJSOP12-Feb-10 8:27
professional#realJSOP12-Feb-10 8:27 
GeneralRe: Creating a live service in c# Pin
#realJSOP14-Feb-10 8:19
professional#realJSOP14-Feb-10 8:19 
Questionaspx to Html page Pin
It_tech11-Feb-10 1:19
It_tech11-Feb-10 1:19 
AnswerRe: aspx to Html page Pin
loyal ginger11-Feb-10 1:33
loyal ginger11-Feb-10 1:33 
GeneralRe: aspx to Html page Pin
It_tech11-Feb-10 1:42
It_tech11-Feb-10 1:42 
GeneralRe: aspx to Html page Pin
It_tech11-Feb-10 2:46
It_tech11-Feb-10 2:46 
GeneralRe: aspx to Html page Pin
loyal ginger11-Feb-10 3:36
loyal ginger11-Feb-10 3:36 
GeneralRe: aspx to Html page Pin
It_tech11-Feb-10 4:07
It_tech11-Feb-10 4:07 
QuestionWebcam in c# Pin
aligokdemir11-Feb-10 0:44
aligokdemir11-Feb-10 0:44 
AnswerRe: Webcam in c# Pin
annathor11-Feb-10 1:45
annathor11-Feb-10 1:45 
AnswerRe: Webcam in c# Pin
Mark H Bishop11-Feb-10 2:09
Mark H Bishop11-Feb-10 2:09 
GeneralRe: Webcam in c# Pin
aligokdemir11-Feb-10 6:19
aligokdemir11-Feb-10 6:19 
GeneralRe: Webcam in c# Pin
Mark H Bishop11-Feb-10 7:07
Mark H Bishop11-Feb-10 7:07 
QuestionC Compiler Using C#3.0 Pin
Niungareamit11-Feb-10 0:00
Niungareamit11-Feb-10 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.