Click here to Skip to main content
15,904,935 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to close all form but not application.exit() Pin
nuttynibbles11-Feb-10 5:21
nuttynibbles11-Feb-10 5:21 
GeneralRe: How to close all form but not application.exit() Pin
OriginalGriff11-Feb-10 5:32
mveOriginalGriff11-Feb-10 5:32 
GeneralRe: How to close all form but not application.exit() Pin
nuttynibbles11-Feb-10 5:46
nuttynibbles11-Feb-10 5:46 
GeneralRe: How to close all form but not application.exit() Pin
OriginalGriff11-Feb-10 5:55
mveOriginalGriff11-Feb-10 5:55 
GeneralRe: How to close all form but not application.exit() Pin
nuttynibbles11-Feb-10 6:02
nuttynibbles11-Feb-10 6:02 
AnswerRe: How to close all form but not application.exit() Pin
#realJSOP11-Feb-10 6:00
professional#realJSOP11-Feb-10 6:00 
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 
Let me first start with what I am trying to accomplish and what I have.

I created a computer management console for active directory. You launch, it gets all computer objects from AD. When you click the computer object, some panels become visible and thre are 3 listbviews. One for Installed Applications, One for Services, and one for Hard drive information. All of that information is retrieved by WMI.

So the way I have it is when you click a computer object, it attempts to contact the computer using seperate threads for each thing (applications, services, hd info).

I have something like this:

// Threading for getting WMI information
Thread m_workerThread1;
Thread m_workerThread2;
Thread m_workerThread3;
Semaphore resourceLock;


When you click comp:

if (m_workerThread1 != null && m_workerThread1.IsAlive)
    m_workerThread1.Abort();

if (m_workerThread2 != null && m_workerThread2.IsAlive)
    m_workerThread2.Abort();

if (m_workerThread3 != null && m_workerThread3.IsAlive)
    m_workerThread3.Abort();

lstServices.BeginUpdate();
lstServices.Items.Clear();

m_workerThread1 = new Thread(new ParameterizedThreadStart(GetRunningServices));
m_workerThread1.IsBackground = true;
m_workerThread1.Start(comp.DnsHostName);

lstApplications.BeginUpdate();
lstApplications.Items.Clear();

m_workerThread2 = new Thread(new ParameterizedThreadStart(GetInstalledApps));
m_workerThread2.IsBackground = true;
m_workerThread2.Start(comp.DnsHostName);

lstDiskDrives.BeginUpdate();
lstDiskDrives.Items.Clear();

m_workerThread3 = new Thread(new ParameterizedThreadStart(GetCompInfo));
m_workerThread3.IsBackground = true;
m_workerThread3.Start(comp.DnsHostName);


And under each method (you see I am calling three different ones) I am using the resourceLock.WaitOne(); and under a try catch finally (in the finally) I am releasing it.

You might be wondering why I call abort. This is because I really couldn't think of a better way to abort the current operation if the user clicks another computer. Having it wait until its done before letting the user choose another computer really isn't an option (because WMI can take a while sometimes).

My problem is if you close the form while these threads are running. Right now I forgot to include anything for it and it causes teh app to crash.

Is there a good way to abort these and then close? Like without displaying a message for the user to wait and try again until it aborts? What is the "best practice" for handling something like this? Or did I just mess the whole system up the way I did it?
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 
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 

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.