Thread.Abort() on a thread executing a Finally/Catch or .ctor block.

Issue: If a thread t is in some catch or finally or cctor block, calling t.Abort() from another thread does not have any effect on the thread. Here is the code to repro this.using System;using System.Threading;namespace ConsoleApplication2{class Program{static Thread t;[STAThread]static void Main(string[] args){Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);t = new Thread(ChildThread);t.Start();t.Join();}static void ChildThread(){try{throw new Exception();}catch (Exception){try{Console.WriteLine(“going to…

4

Profiling: Sampling doesn’t report my functions wait time.

Working on performance of VSSConverter. I am using the new F1 profiler being shipped with VS 2005. I have a simple code sample like this: using System;using System.Collections.Generic;using System.Text;using System.Threading;namespace perf_test{class Program{static bool exit = false;static object lockObject = 3;static void Main(string[] args){Thread threadWait = new Thread(new ThreadStart(WaitMethod));Thread threadProcess = new Thread(new ThreadStart(ProcessMethod));threadWait.Start();threadProcess.Start();threadWait.Join();threadProcess.Join();}static void WaitMethod(){lock…


How to stop threads on threadpool when my windows service is being stopped?

I came accross a mail thread which deals with the problem i was facing some time back. Sharing it to you all. Problem: I have written a windows service in .Net that uses the ThreadPool.QueueUserWorkItem() call to do some processing. Each work item to the thread pool takes the same type of object to process…

1

Path.GetTempFileName()

In C# the class Path gives an easy way to get a temporary file for your application but you have to be careful using this API. This API create zero-byte temporary files in Windows temporary folder and when there are 65536 files it gives an IOException saying “The file exists.”. But if you need small number of temporary…

2