Click here to Skip to main content
15,895,809 members
Home / Discussions / C#
   

C#

 
GeneralRe: Collection within a Collection and "loading" advice Pin
Jon Rista27-Oct-02 17:48
Jon Rista27-Oct-02 17:48 
Questionthread.Abort() doesn't work????? Pin
fftongzhi22-Oct-02 15:23
fftongzhi22-Oct-02 15:23 
AnswerRe: thread.Abort() doesn't work????? Pin
Paul Riley23-Oct-02 0:17
Paul Riley23-Oct-02 0:17 
GeneralRe: thread.Abort() doesn't work????? Pin
James T. Johnson23-Oct-02 0:58
James T. Johnson23-Oct-02 0:58 
GeneralRe: thread.Abort() doesn't work????? Pin
fftongzhi23-Oct-02 16:04
fftongzhi23-Oct-02 16:04 
GeneralRe: thread.Abort() doesn't work????? Pin
James T. Johnson23-Oct-02 16:57
James T. Johnson23-Oct-02 16:57 
GeneralRe: thread.Abort() doesn't work????? Pin
fftongzhi23-Oct-02 18:51
fftongzhi23-Oct-02 18:51 
GeneralRe: thread.Abort() doesn't work????? Pin
Jon Rista23-Oct-02 17:51
Jon Rista23-Oct-02 17:51 
Thread.Abort() does work...its just fickle. Its also pretty much required that you catch the ThreadAbortException that Thread.Abort() throws. Its also a good idea to call Thread.Join() immediately after your call to Thread.Abort(). Thread.Join() will cause the calling thread to wait indefinitely until the child thread terminates. If you do not put Thread.Join() in, the application can exit before the child thread does, in which case the child thread will most likely never exit. The reason for this is the application repeatedly fires off the ThreadAbortException until its actully caught and dealt with. When the application exits, the ThreadAbortException can no longer be thrown, resulting in a dead thread that won't go away. I tried this, and it seemed to work fine (I tried 5 times, properly exited every time):

using System;
using System.Threading;

namespace TestThreadAbort
{
	class TheTest
	{
		[STAThread]
		static void Main(string[] args)
		{
			Console.WriteLine("[M] Starting worker thread.");
			Thread t = new Thread(new ThreadStart(WorkerThread));
			t.Start();
			Thread.Sleep(170000);
			Console.WriteLine("[M] Killing WorkerThread...");
			t.Abort();
			Console.WriteLine("[M] Main thread waiting...");
			t.Join();
			Console.WriteLine("[M] Goodbye.");
		}

		private static void WorkerThread()
		{
			try
			{
				while (true)
				{
					Console.WriteLine("[W] WorkerThread saying hello.");
					Thread.Sleep(50000);
				}
			}
			catch (ThreadAbortException)
			{
				Console.WriteLine("[W] WorkerThread saying bye-bye.");
			}
		}
	}
}

GeneralRe: thread.Abort() doesn't work????? Pin
James T. Johnson23-Oct-02 18:39
James T. Johnson23-Oct-02 18:39 
GeneralHelp about .NET windows service solutions Pin
Member 13227322-Oct-02 5:07
Member 13227322-Oct-02 5:07 
Questionplease try it...see what happens...is it a bug? Pin
Atilla Selem22-Oct-02 4:36
Atilla Selem22-Oct-02 4:36 
AnswerRe: please try it...see what happens...is it a bug? Pin
Daniel Turini22-Oct-02 4:43
Daniel Turini22-Oct-02 4:43 
GeneralRe: please try it...see what happens...is it a bug? Pin
Atilla Selem22-Oct-02 5:51
Atilla Selem22-Oct-02 5:51 
Generalcoding conventions.... Pin
waleed riaz21-Oct-02 22:18
waleed riaz21-Oct-02 22:18 
GeneralRe: coding conventions.... Pin
Stephane Rodriguez.21-Oct-02 22:28
Stephane Rodriguez.21-Oct-02 22:28 
GeneralRe: coding conventions.... Pin
Daniel Turini21-Oct-02 22:30
Daniel Turini21-Oct-02 22:30 
GeneralRe: coding conventions.... Pin
waleed riaz22-Oct-02 9:35
waleed riaz22-Oct-02 9:35 
GeneralRe: coding conventions.... Pin
Daniel Turini22-Oct-02 10:02
Daniel Turini22-Oct-02 10:02 
GeneralRe: coding conventions.... Pin
waleed riaz22-Oct-02 21:52
waleed riaz22-Oct-02 21:52 
GeneralRe: coding conventions.... Pin
Kevin McFarlane24-Oct-02 7:33
Kevin McFarlane24-Oct-02 7:33 
GeneralRe: coding conventions.... Pin
waleed riaz24-Oct-02 19:04
waleed riaz24-Oct-02 19:04 
GeneralRe: coding conventions.... Pin
Kevin McFarlane25-Oct-02 0:07
Kevin McFarlane25-Oct-02 0:07 
GeneralRe: coding conventions.... Pin
Furty25-Oct-02 15:39
Furty25-Oct-02 15:39 
GeneralRe: coding conventions.... Pin
LongRange.Shooter28-Oct-02 11:02
LongRange.Shooter28-Oct-02 11:02 
GeneralRe: coding conventions.... Pin
waleed riaz28-Oct-02 18:31
waleed riaz28-Oct-02 18:31 

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.