New thread reference lost, can't abort

  • Thread starter Thread starter Donald Adams
  • Start date Start date
D

Donald Adams

I have a Main thread that starts a named thread,
that inits and starts up events for watch a folder and monitoring a
schedule.
Later, I want to join the thread to the main thread and disable the events
or if need be abort the thread. However, the named thread continues to run
but loses it's name and main thread cannot abort it anymore.

What's happening and how can I keep a reference to it? It seems to get lost
after initializing.

Thanks in Advance,
Byron
 
Hi Donald,

You can probably store a reference to the instance of the Thread class in
some private variable.
 
Hi Dmitriy,

I have done that, here's some code:

{
....
private Cana.Service.Manager _csManager;
private Thread _tService;
....
private void ServiceStart()
{
_csManager=new My.Service.Manager();
_tService=new Thread(new ThreadStart(_csManager.Start));
_tService.Name="Manager";
_tService.Start();
_IsRunning=true;
SetButtonState(_IsRunning);
}
private void ServiceStop()
{
_tService.Abort();
_tService.Join();
_csManager.Dispose(true);
_tService=null;
_csManager=null;
_IsRunning=false;
SetButtonState(_IsRunning);
}
}

It seems that the system things the 'named' thread is finished when the
constructor method of my object is completed. Then you can see the thread
still there, but no name and no chance to .abort it with the
_tService.Abort(); statement.
How can I keep this reference?

Thanks in Advance,
Byron.


Dmitriy Lapshin said:
Hi Donald,

You can probably store a reference to the instance of the Thread class in
some private variable.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Donald Adams said:
I have a Main thread that starts a named thread,
that inits and starts up events for watch a folder and monitoring a
schedule.
Later, I want to join the thread to the main thread and disable the events
or if need be abort the thread. However, the named thread continues to run
but loses it's name and main thread cannot abort it anymore.

What's happening and how can I keep a reference to it? It seems to get lost
after initializing.

Thanks in Advance,
Byron
 
You will need to provide a simple version of the thread method you call
_csManager.Start. It's probably exiting as soon as it is started.

Donald Adams said:
Hi Dmitriy,

I have done that, here's some code:

{
...
private Cana.Service.Manager _csManager;
private Thread _tService;
...
private void ServiceStart()
{
_csManager=new My.Service.Manager();
_tService=new Thread(new ThreadStart(_csManager.Start));
_tService.Name="Manager";
_tService.Start();
_IsRunning=true;
SetButtonState(_IsRunning);
}
private void ServiceStop()
{
_tService.Abort();
_tService.Join();
_csManager.Dispose(true);
_tService=null;
_csManager=null;
_IsRunning=false;
SetButtonState(_IsRunning);
}
}

It seems that the system things the 'named' thread is finished when the
constructor method of my object is completed. Then you can see the thread
still there, but no name and no chance to .abort it with the
_tService.Abort(); statement.
How can I keep this reference?

Thanks in Advance,
Byron.


Dmitriy Lapshin said:
Hi Donald,

You can probably store a reference to the instance of the Thread class in
some private variable.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Donald Adams said:
I have a Main thread that starts a named thread,
that inits and starts up events for watch a folder and monitoring a
schedule.
Later, I want to join the thread to the main thread and disable the events
or if need be abort the thread. However, the named thread continues
to
run
but loses it's name and main thread cannot abort it anymore.

What's happening and how can I keep a reference to it? It seems to get lost
after initializing.

Thanks in Advance,
Byron
 
Back
Top