Click here to Skip to main content
15,905,683 members
Home / Discussions / C#
   

C#

 
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 PinPopular
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 
AnswerRe: developing with sql server Pin
PIEBALDconsult15-Jan-10 12:02
mvePIEBALDconsult15-Jan-10 12:02 
GeneralRe: developing with sql server Pin
teknolog12316-Jan-10 6:54
teknolog12316-Jan-10 6:54 
GeneralRe: developing with sql server Pin
PIEBALDconsult17-Jan-10 5:11
mvePIEBALDconsult17-Jan-10 5:11 
GeneralRe: developing with sql server Pin
teknolog12320-Jan-10 11:31
teknolog12320-Jan-10 11:31 
AnswerRe: developing with sql server Pin
ZHAOBING_NTU15-Jan-10 19:06
ZHAOBING_NTU15-Jan-10 19:06 
QuestionComboBox DropDownWidth behaviour Pin
baranils15-Jan-10 8:36
baranils15-Jan-10 8:36 
Questionsend mail to yahoo Pin
mohd_mogaly15-Jan-10 6:58
mohd_mogaly15-Jan-10 6:58 
AnswerRe: send mail to yahoo Pin
dan!sh 15-Jan-10 8:37
professional dan!sh 15-Jan-10 8:37 
QuestionJagged Arrays Definition Pin
Sokka9315-Jan-10 5:35
Sokka9315-Jan-10 5:35 
AnswerRe: Jagged Arrays Definition Pin
Rick Shaub15-Jan-10 5:52
Rick Shaub15-Jan-10 5:52 

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.