Click here to Skip to main content
15,888,330 members
Home / Discussions / C#
   

C#

 
GeneralRe: Waiting for thread to exit? Pin
Eddy Vluggen9-Nov-14 5:59
professionalEddy Vluggen9-Nov-14 5:59 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:31
SledgeHammer019-Nov-14 7:31 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:28
SledgeHammer019-Nov-14 7:28 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 5:59
mvePIEBALDconsult9-Nov-14 5:59 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak9-Nov-14 7:08
mveDave Kreskowiak9-Nov-14 7:08 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:48
SledgeHammer019-Nov-14 7:48 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak9-Nov-14 10:31
mveDave Kreskowiak9-Nov-14 10:31 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 11:18
SledgeHammer019-Nov-14 11:18 
It's actually a pretty similar scenario to a logging API, an asynchronous one. Think about Log4Net or NLog or whatever. They have an email listener for example. That's going to be "slow". But regardless, lets say your console app writes 1000 log entries to the log, the Log() method is going to return right away because its async. So the main thread is going to be done and exit after like a second, but its going to take the logger a minute or two or whatever to send all those emails. Yes, I could have a design like:

theLogger.Flush(); / theLogger.Shutdown();

and have that method block the main thread until its done.

or I can do what you said:

theLogger.OnComplete += blah...

and have the blah method block the main process. But I see a few issues with both of those methods IMHO

1) Just like my queue implementation, a logger queue isn't going to have log entries to write all the time... how is the logger to know when to send the OnComplete() notification? Lets say you send it every time the queue goes empty... ok, well, now you require even more work on the developers part as they have to know if this OnComplete() event is the one they really care about and then they have to couple that with some mechanism to block the thread. Then as the developer of the API, you're going to get blamed cuz the developer didn't implement it right!

2) the .Flush() / .Shutdown() / etc. is cleaner and much less error prone, but this requires the developer to remember to call .Flush() / .Complete() and of course, you'll get blamed for a "buggy framework" when they forget because "your framework should handle this automatically -- hanging is a 'bug'".

3) finally, and this kind of a nitpick on my part... I see a logger (and my queue) as a fire & forget thing... I don't care about getting logging notifications back, I don't care about whether the logging queue is empty or not, I don't want to concern myself with any of that. I simply want to call Log("whatever") and move on with my life. Same thing with my queue.

This is what I'm trying to implement here... a mechanism that'll shut down the queue automatically.
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:37
SledgeHammer019-Nov-14 7:37 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 7:54
mvePIEBALDconsult9-Nov-14 7:54 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:57
SledgeHammer019-Nov-14 7:57 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 8:00
SledgeHammer019-Nov-14 8:00 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 8:13
mvePIEBALDconsult9-Nov-14 8:13 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 8:49
SledgeHammer019-Nov-14 8:49 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 8:55
mvePIEBALDconsult9-Nov-14 8:55 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 9:17
SledgeHammer019-Nov-14 9:17 
GeneralRe: Waiting for thread to exit? Pin
Eddy Vluggen10-Nov-14 8:34
professionalEddy Vluggen10-Nov-14 8:34 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer0110-Nov-14 9:27
SledgeHammer0110-Nov-14 9:27 
GeneralRe: Waiting for thread to exit? Pin
Eddy Vluggen11-Nov-14 0:31
professionalEddy Vluggen11-Nov-14 0:31 
AnswerRe: Waiting for thread to exit? Pin
Garth J Lancaster8-Nov-14 17:31
professionalGarth J Lancaster8-Nov-14 17:31 
QuestionAny library to decompress XZ files? Pin
DonRolando8-Nov-14 9:56
DonRolando8-Nov-14 9:56 
AnswerRe: Any library to decompress XZ files? Pin
Garth J Lancaster8-Nov-14 12:11
professionalGarth J Lancaster8-Nov-14 12:11 
QuestionSystem.Web.HttpContext cannot be serialized because it does not have a parameterless constructor. Pin
ASPnoob8-Nov-14 4:33
ASPnoob8-Nov-14 4:33 
AnswerRe: System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor. Pin
Kornfeld Eliyahu Peter8-Nov-14 9:19
professionalKornfeld Eliyahu Peter8-Nov-14 9:19 
QuestionBlocking Collection Issue Pin
SledgeHammer017-Nov-14 8:24
SledgeHammer017-Nov-14 8:24 

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.