HighTechTalks DotNet Forums  

Delegate Dies

Dotnet General Discussions microsoft.public.dotnet.general


Discuss Delegate Dies in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
John
 
Posts: n/a

Default Delegate Dies - 12-10-2007 , 02:59 PM






I'm using the FileSystemWatcher class to get notified when a file is
created:

myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler);

Sometimes (though rarely), myHandler executes fine. However, most of the
time it appears to die on the first line of execution:

private void myHandler(object source, FileSystemEventArgs e)
{
try
{
Thread.Sleep(4000);
// Do more stuff
}
catch(Exception aException)
{
// This never get called
}
}

If I set a breakpoint on the line:
Thread.Sleep(4000);

It takes a long time for VS2005 to break. However, when it does, everything
looks fine (as far as parameters, registers, etc.). I don't know if I'm
overflowing the stack somehow, or why it is dying.

Does anybody have any ideas? Thanks,
-- John




Reply With Quote
  #2  
Old   
RobertW
 
Posts: n/a

Default RE: Delegate Dies - 12-10-2007 , 03:25 PM






Umm.. What's creating the file(s)?

I didn't look it up in the documentation, but from what you wrote, I gather
this function will be called whenever a file (or any file?) is created (i.e.
not updated or modified, just created from a deleted or non-existent file).

I'm going to guess your file(s) aren't being created too often, and only
when a file is created is your event handler being reached. i.e. the event
handler isn't the problem.

But honestly, I don't think you gave enough sample code or information to
know that one way or the other.

-Rob

"John" wrote:

Quote:
I'm using the FileSystemWatcher class to get notified when a file is
created:

myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler);

Sometimes (though rarely), myHandler executes fine. However, most of the
time it appears to die on the first line of execution:

private void myHandler(object source, FileSystemEventArgs e)
{
try
{
Thread.Sleep(4000);
// Do more stuff
}
catch(Exception aException)
{
// This never get called
}
}

If I set a breakpoint on the line:
Thread.Sleep(4000);

It takes a long time for VS2005 to break. However, when it does, everything
looks fine (as far as parameters, registers, etc.). I don't know if I'm
overflowing the stack somehow, or why it is dying.

Does anybody have any ideas? Thanks,
-- John





Reply With Quote
  #3  
Old   
John
 
Posts: n/a

Default Re: Delegate Dies - 12-10-2007 , 05:07 PM



Hey Rob,

All of your assumptions are correct. I don't think the event handler is the
problem either. I'm actually completely uncertain where to even begin to
look though. I have no idea why the code would just all of the sudden die
in that thread. I didn't write all of the code for this project, I'm just
the guy that has to maintain it.

Any other random ideas why a thread would all of the sudden just die?



"RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote

Quote:
Umm.. What's creating the file(s)?

I didn't look it up in the documentation, but from what you wrote, I
gather
this function will be called whenever a file (or any file?) is created
(i.e.
not updated or modified, just created from a deleted or non-existent
file).

I'm going to guess your file(s) aren't being created too often, and only
when a file is created is your event handler being reached. i.e. the
event
handler isn't the problem.

But honestly, I don't think you gave enough sample code or information to
know that one way or the other.

-Rob

"John" wrote:

I'm using the FileSystemWatcher class to get notified when a file is
created:

myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler);

Sometimes (though rarely), myHandler executes fine. However, most of the
time it appears to die on the first line of execution:

private void myHandler(object source, FileSystemEventArgs e)
{
try
{
Thread.Sleep(4000);
// Do more stuff
}
catch(Exception aException)
{
// This never get called
}
}

If I set a breakpoint on the line:
Thread.Sleep(4000);

It takes a long time for VS2005 to break. However, when it does,
everything
looks fine (as far as parameters, registers, etc.). I don't know if I'm
overflowing the stack somehow, or why it is dying.

Does anybody have any ideas? Thanks,
-- John







Reply With Quote
  #4  
Old   
RobertW
 
Posts: n/a

Default Re: Delegate Dies - 12-10-2007 , 05:34 PM



Ok, Random thoughts I'm good with... Useful ? Eh..

From what I understand about threads, and I don't do a whole lot of
multithreaded programming (the work I do wouldn't benefit that much from it,
though I do it in some areas like background loading of data):

-Event handling should happen in the main thread, and when the main thread
exits, the program exits.
-If you want a sub-thread or new-thread to handle an event, you catch the
event in the main thread, then in the event handler, call a 'real event
handler' in a new thread (i.e. create a new thread for that purpose), and
return immediately so the flow of control returns normally to the main thread.

So, when you say 'the thread dies' I'm not sure if you mean a sub-thread
dies or the main program thread dies. If the whole program dies, then that's
a bigger problem you may need to troubleshoot with a debugging tool to find
what causes the main program to exit.

This is not based on specific knowledge of threading in .net, but rather
older threading models I've used.

-Rob

"John" wrote:

Quote:
Hey Rob,

All of your assumptions are correct. I don't think the event handler is the
problem either. I'm actually completely uncertain where to even begin to
look though. I have no idea why the code would just all of the sudden die
in that thread. I didn't write all of the code for this project, I'm just
the guy that has to maintain it.

Any other random ideas why a thread would all of the sudden just die?



"RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote in message
news:7AC9113E-04F2-47A8-AC18-A1C84E7D301F (AT) microsoft (DOT) com...
Umm.. What's creating the file(s)?

I didn't look it up in the documentation, but from what you wrote, I
gather
this function will be called whenever a file (or any file?) is created
(i.e.
not updated or modified, just created from a deleted or non-existent
file).

I'm going to guess your file(s) aren't being created too often, and only
when a file is created is your event handler being reached. i.e. the
event
handler isn't the problem.

But honestly, I don't think you gave enough sample code or information to
know that one way or the other.

-Rob

"John" wrote:

I'm using the FileSystemWatcher class to get notified when a file is
created:

myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler);

Sometimes (though rarely), myHandler executes fine. However, most of the
time it appears to die on the first line of execution:

private void myHandler(object source, FileSystemEventArgs e)
{
try
{
Thread.Sleep(4000);
// Do more stuff
}
catch(Exception aException)
{
// This never get called
}
}

If I set a breakpoint on the line:
Thread.Sleep(4000);

It takes a long time for VS2005 to break. However, when it does,
everything
looks fine (as far as parameters, registers, etc.). I don't know if I'm
overflowing the stack somehow, or why it is dying.

Does anybody have any ideas? Thanks,
-- John








Reply With Quote
  #5  
Old   
John
 
Posts: n/a

Default Re: Delegate Dies - 12-10-2007 , 08:11 PM



Hmmm....

This appeared to only happen when I had a breakpoint set. If I uncheck all
of my breakpoints, everything works fine. For now, I'm going to blame this
on some exception checking in VS2005. Only because I have no other idea at
the moment how to track this down if a problem does exist.



"RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote

Quote:
Ok, Random thoughts I'm good with... Useful ? Eh..

From what I understand about threads, and I don't do a whole lot of
multithreaded programming (the work I do wouldn't benefit that much from
it,
though I do it in some areas like background loading of data):

-Event handling should happen in the main thread, and when the main thread
exits, the program exits.
-If you want a sub-thread or new-thread to handle an event, you catch the
event in the main thread, then in the event handler, call a 'real event
handler' in a new thread (i.e. create a new thread for that purpose), and
return immediately so the flow of control returns normally to the main
thread.

So, when you say 'the thread dies' I'm not sure if you mean a sub-thread
dies or the main program thread dies. If the whole program dies, then
that's
a bigger problem you may need to troubleshoot with a debugging tool to
find
what causes the main program to exit.

This is not based on specific knowledge of threading in .net, but rather
older threading models I've used.

-Rob

"John" wrote:

Hey Rob,

All of your assumptions are correct. I don't think the event handler is
the
problem either. I'm actually completely uncertain where to even begin to
look though. I have no idea why the code would just all of the sudden
die
in that thread. I didn't write all of the code for this project, I'm
just
the guy that has to maintain it.

Any other random ideas why a thread would all of the sudden just die?



"RobertW" <RobertW (AT) discussions (DOT) microsoft.com> wrote in message
news:7AC9113E-04F2-47A8-AC18-A1C84E7D301F (AT) microsoft (DOT) com...
Umm.. What's creating the file(s)?

I didn't look it up in the documentation, but from what you wrote, I
gather
this function will be called whenever a file (or any file?) is created
(i.e.
not updated or modified, just created from a deleted or non-existent
file).

I'm going to guess your file(s) aren't being created too often, and
only
when a file is created is your event handler being reached. i.e. the
event
handler isn't the problem.

But honestly, I don't think you gave enough sample code or information
to
know that one way or the other.

-Rob

"John" wrote:

I'm using the FileSystemWatcher class to get notified when a file is
created:

myFileSystemWatcher.Created += new FileSystemEventHandler(myHandler);

Sometimes (though rarely), myHandler executes fine. However, most of
the
time it appears to die on the first line of execution:

private void myHandler(object source, FileSystemEventArgs e)
{
try
{
Thread.Sleep(4000);
// Do more stuff
}
catch(Exception aException)
{
// This never get called
}
}

If I set a breakpoint on the line:
Thread.Sleep(4000);

It takes a long time for VS2005 to break. However, when it does,
everything
looks fine (as far as parameters, registers, etc.). I don't know if
I'm
overflowing the stack somehow, or why it is dying.

Does anybody have any ideas? Thanks,
-- John










Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.