Leaving threads open??

G

Guest

Hi there,

Have an issue with my .NET application.

Basically the problem is it runs fine the first time and then when i close
it (from settings > memory) it no longer starts when i click on the icon,
literally does nothing.

This started happening after i'm now using notifications to run a specific
thread every 5 minutes.

In my form_closing event i run this code:


if ( timedSyncThread != null )
{
EventWaitHandle notifyEvent = new OpenNETCF.Threading.EventWaitHandle(
false,
OpenNETCF.Threading.EventResetMode.AutoReset,
"SAMS_SYNC_EVENT" );

// Notify the thread to stop.
notifyEvent.Set();

notifyEvent.Close();

...but i still have this problem.

Any ideas?

PS. Works fine again after a soft reset.
 
C

Chris Tacke, eMVP

I don't see the thread side of this? How does it receive the notice to end
and then exit itself?

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
G

Guest

Thanks for the reply Chris, although i'm not totally sure what more i can
say to explain the problem.

It's opening a new thread with this line of code:

timedSyncThread = new OpenNETCF.Threading.ThreadEx(new
ThreadStart(this.SetSyncTime));
timedSyncThread.Start();

and it does that every 5 minutes.

on the closing event of my application it attempts to close that thread but
the application just doesn't re-open until i soft-reset.

What could be causing that?

Many Thanks,
Rob
 
S

Steve Maillet \(eMVP\)

You still aren't showing the code of the thread itself. That's likely
causing a problem. (BTW: Why start a new thread every 5 minutes in response
to a notification? Why not just do whatever needs to be done in the
notification handler?)
 
C

Chris Tacke, eMVP

So you're creating a new thread every 5 minutes? What are these threads
doing? How does the thread procedure exit? How does the main app ensure
they are all closed at startup? What I'm saying is we need to see the
architecture of the threads. I'm certain that they're still running when
your app closes, and this is what's preventing you from restarting.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
P

Paul G. Tobey [eMVP]

It's not a matter of closing the thread handle, but *having the thread
exit*. See what I mean?

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top