Click here to Skip to main content
15,921,959 members
Home / Discussions / C#
   

C#

 
AnswerMessage Closed Pin
15-Jan-10 20:49
stancrm15-Jan-10 20:49 
GeneralRe: DirectX Support In C#.Net Pin
ashwath197916-Jan-10 0:32
ashwath197916-Jan-10 0:32 
GeneralMessage Closed Pin
16-Jan-10 1:02
stancrm16-Jan-10 1:02 
GeneralRe: DirectX Support In C#.Net Pin
ashwath197916-Jan-10 1:10
ashwath197916-Jan-10 1:10 
GeneralRe: DirectX Support In C#.Net Pin
#realJSOP16-Jan-10 1:21
professional#realJSOP16-Jan-10 1:21 
QuestionUser Interface for Windows Form Pin
sjs4u15-Jan-10 18:21
sjs4u15-Jan-10 18:21 
AnswerRe: User Interface for Windows Form Pin
N a v a n e e t h15-Jan-10 18:38
N a v a n e e t h15-Jan-10 18:38 
AnswerRe: User Interface for Windows Form Pin
Abhinav S15-Jan-10 19:51
Abhinav S15-Jan-10 19:51 
QuestionHow to retrieve lost email password Pin
CoderForEver15-Jan-10 17:28
CoderForEver15-Jan-10 17:28 
AnswerRe: How to retrieve lost email password Pin
Dave Kreskowiak15-Jan-10 18:42
mveDave Kreskowiak15-Jan-10 18:42 
GeneralRe: How to retrieve lost email password Pin
CoderForEver16-Jan-10 5:09
CoderForEver16-Jan-10 5:09 
GeneralRe: How to retrieve lost email password Pin
Dave Kreskowiak16-Jan-10 6:28
mveDave Kreskowiak16-Jan-10 6:28 
GeneralRe: How to retrieve lost email password Pin
CoderForEver16-Jan-10 18:24
CoderForEver16-Jan-10 18:24 
GeneralRe: How to retrieve lost email password Pin
Dave Kreskowiak16-Jan-10 19:38
mveDave Kreskowiak16-Jan-10 19:38 
GeneralRe: How to retrieve lost email password Pin
Not Active16-Jan-10 6:34
mentorNot Active16-Jan-10 6:34 
AnswerRe: How to retrieve lost email password Pin
Alex Manolescu16-Jan-10 7:51
Alex Manolescu16-Jan-10 7:51 
QuestionMonitoring of threads Pin
justwithit15-Jan-10 11:15
justwithit15-Jan-10 11:15 
AnswerRe: Monitoring of threads Pin
Luc Pattyn15-Jan-10 12:41
sitebuilderLuc Pattyn15-Jan-10 12:41 
in situations like that, and many others, what I do is add logging code; these are basically calls to a lightweight log method emitting a single line of text with a lot of information, typically time of day, threadID, and a string that is passed to the log method, describing where in the code the log is happening.

I often log to a ListBox (in a WinForms app), to the Console (when running under Visual Studio), or to a file; and often a combination of those (ListBox/Console are fine while the app runs, file is OK to keep a record).
BTW: for file logging I typically use File.AppendText which means the file is always closed, and is intact, up to the last log message, even when the app crashes.

Having log files you can watch what was happening at or around the problem point, and compare the sequence of events with others.

Once you have a single log describing a failure, you can:
- run again till the next failure, and compare failures;
- add log statements in and around suspected areas in the code;
- add assertion statements (checking invariants, things that should be true, and only logging when they aren't);
- try and find ways to up the failure frequency, which also means the waiting period between failures goes down, so you capture more information in less time.

The overall philosophy is: improve observability.
So with a threading/deadlock problem, I would add log statements to every thread-related call (thread creation, thread joins, start and end of important methods, etc). I would generate as much as 1000 logs per second, if that is required.

This special way of debugging beats the regular breakpoint/single-step approach in that it is much more automated and a lot faster; it is essential to solve problems that take a long time to occur, and/or seem to be rather random.

BTW: it could be that you are facing another problem, here are a few candidates:
- not enough error handling: something is throwing without you noticing; make sure you have all the try-catches you need; put a try-catch in the staic Main() as a safety net; install an Application.ThreadException handler. Don't ever have an empty catch block, at least log the exception.
- running out of memory; logging Environment.WorkingSet periodically (with a Windows.Forms.Timer) could be very helpful (although it might miss a "large-object-heap" fragmentation problem.
- a thread synchronization problem: lacking a lock somewhere makes your app use an invalid combination of state variable values (these may be the hardest to figure out as they very much depend on timing).

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

Happy New Year to all.
We hope 2010 soon brings us automatic PRE tags!
Until then, please insert them manually.


GeneralRe: Monitoring of threads Pin
Garth J Lancaster15-Jan-10 12:57
professionalGarth J Lancaster15-Jan-10 12:57 
GeneralRe: Monitoring of threads Pin
Luc Pattyn15-Jan-10 13:39
sitebuilderLuc Pattyn15-Jan-10 13:39 
GeneralRe: Monitoring of threads Pin
Roger Wright15-Jan-10 17:16
professionalRoger Wright15-Jan-10 17:16 
GeneralRe: Monitoring of threads Pin
Luc Pattyn15-Jan-10 17:31
sitebuilderLuc Pattyn15-Jan-10 17:31 
GeneralRe: Monitoring of threads Pin
justwithit17-Jan-10 3:06
justwithit17-Jan-10 3:06 
GeneralRe: Monitoring of threads Pin
Luc Pattyn17-Jan-10 3:25
sitebuilderLuc Pattyn17-Jan-10 3:25 
Questiondeveloping with sql server Pin
teknolog12315-Jan-10 9:40
teknolog12315-Jan-10 9:40 

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.