G
Gaetan
Hi
let this code :
using System;
using System.Threading;
namespace ThisNamespace
{
class ThisClass
{
static void Main()
{
new ThisClass();
// here the end of the application => should call the
"destructor"
}
public ThisClass()
{
StartThread();
}
// finaliser
~ThisClass()
{
_WorkingThread.Abort();
}
Thread _WorkingThread;
public void StartThread()
{
_WorkingThread = new Thread( new ThreadStart(DoWork));
_WorkingThread.Start();
// if you remove this Start(), the "destructor" is well
called...
}
void DoWork()
{
while(true)
;
}
}
}
This is a simple example of what i would like to do: a class that
launch an other thread in this constructor, this thread doint whatever
it wants.
But when the application is closed, the thread should be destroyed
(properly by calling _WorkingThread.Abort in the "destructor"). But
this destructor is not called and so, I cannot stop my thread, and
this result with an executable still launched !!!
Any idea please?
PS: and please, no ThreadPool based answer...
let this code :
using System;
using System.Threading;
namespace ThisNamespace
{
class ThisClass
{
static void Main()
{
new ThisClass();
// here the end of the application => should call the
"destructor"
}
public ThisClass()
{
StartThread();
}
// finaliser
~ThisClass()
{
_WorkingThread.Abort();
}
Thread _WorkingThread;
public void StartThread()
{
_WorkingThread = new Thread( new ThreadStart(DoWork));
_WorkingThread.Start();
// if you remove this Start(), the "destructor" is well
called...
}
void DoWork()
{
while(true)
;
}
}
}
This is a simple example of what i would like to do: a class that
launch an other thread in this constructor, this thread doint whatever
it wants.
But when the application is closed, the thread should be destroyed
(properly by calling _WorkingThread.Abort in the "destructor"). But
this destructor is not called and so, I cannot stop my thread, and
this result with an executable still launched !!!
Any idea please?
PS: and please, no ThreadPool based answer...