Willy Denoyette said:
System.Diagnostics.Process.Threads returns a collection of thread in the
process;
using System.Diagnostics;
...
ProcessThreadCollection myThreads = GetCurrentProcess().Threads;
That worked after I changed it to Process.GetCurrentProcess().Threads.
But I thought after the thread left its code it would disappear.
Here are the results of my text:
In loop i = 8 Time: 1/30/2008 5:17:36 PMNumber of Threads: 5 Max
Threads: 50/1000 Available Threads: 50/1000 Current Threads:
System.Diagnostics.ProcessThreadCollection
Status for Thread: ThreadMonitor is Running
Status for Thread: fileWatchThread is Stopped
Status for Thread: fileWatchThread is Stopped
Status for Thread: fileWatchThread is WaitSleepJoin
Status for Thread: fileWatchThread is WaitSleepJoin
AS you can see 2 are stopped and 2 are WaitSleepJoin.
the Number Threads from your method is showing 5 which is the amount of
threads that were spawned, but it never decrements.
Do I need to do something to force this?
In the following you can see the Thread being started when a file hits my
folder. The thread then prints a message and after 60 seconds just ends
(which is where the Stopped is seen in my above results). A few seconds
later the other 2 would also show as stopped. But even after an hour the
number of threads are showing as 5.
*******************************************************
private void OnChanged(object source, FileSystemEventArgs e)
{
fileWatchThread = new Thread(WatchTheFiles);
threadList.Add(fileWatchThread);
fileWatchThread.Name = "fileWatchThread";
fileWatchThread.Start();
}
private void WatchTheFiles()
{
FileStream fs = new FileStream(@"c:\tomsfilewatcher\tomsfilewatcher.txt",
FileMode.Append, System.IO.FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("Something Changed");
sw.Close();
System.Threading.Thread.Sleep(60000);
// File.Move(@"c:\tomstest\tomstest.txt",
@"c:\tomstest2\tomstest.txt");
}
************************************************************
Thanks,
Tom