Click here to Skip to main content
15,903,203 members
Home / Discussions / C#
   

C#

 
AnswerRe: Directory Stream Pin
Xmen Real 15-Apr-09 18:39
professional Xmen Real 15-Apr-09 18:39 
QuestionWatching for Removeable Drives Pin
Jammer15-Apr-09 12:20
Jammer15-Apr-09 12:20 
AnswerRe: Watching for Removeable Drives Pin
Luc Pattyn15-Apr-09 12:42
sitebuilderLuc Pattyn15-Apr-09 12:42 
AnswerRe: Watching for Removeable Drives Pin
Nilesh Hapse15-Apr-09 20:16
Nilesh Hapse15-Apr-09 20:16 
QuestionSocket Connection Shutdown and Close Pin
kikeman15-Apr-09 11:41
kikeman15-Apr-09 11:41 
AnswerRe: Socket Connection Shutdown and Close Pin
Colin Angus Mackay15-Apr-09 12:12
Colin Angus Mackay15-Apr-09 12:12 
GeneralRe: Socket Connection Shutdown and Close Pin
kikeman16-Apr-09 4:45
kikeman16-Apr-09 4:45 
GeneralRe: Socket Connection Shutdown and Close Pin
Colin Angus Mackay16-Apr-09 5:05
Colin Angus Mackay16-Apr-09 5:05 
Going by some of your naming conventions I'm guessing you are coming from a C++/MFC background. That being the case you need to think about things a little differently. Well, I suspect you are, but the pendulum has swung too far the other way. You'll get what I mean in a moment.

If you have something that is disposable then you need to dispose of it rather than let the garbage handler deal with it. Just like you do in C++. This is because if it is disposable it will be holding on to resources (like a socket, file handle, GDI resource, etc.) that needs to be cleaned up as soon as you are finished with it rather than when the garbage collector gets around to it.

Finalizers are not run in any specific sequence and you cannot guarantee that the objects you reference haven't already been finalized. Basically, the CLR is clever enough to realise that if you are unreferenced, then everything you reference that isn't referenced else where is also unreferenced. It essentially chucks it into a big queue and processes it but doesn't care about order

Finalizers are really just a backstop in .NET to ensure that if the developer has forgotten to dispose of something the garbage collector can at least get a chance at dealing with it.

Since you only check for nullability on Sender may already have been closed. According to Socket.Shutdown documentation[^] the exception you are getting is raised if you attempt to shutdown a socket that is already closed.

Rather than call Shutdown and Close, you may just want to call Dispose on the socket object which will clean up the Socket for you and can be called multiple times quite safely. If the interface is implemented implicitly then you can just call Sender.Dispose(). If it is an explicity interface you'll have to use ((IDisposable)Sender).Dispose();

I hope this helps.


GeneralRe: Socket Connection Shutdown and Close Pin
kikeman16-Apr-09 5:39
kikeman16-Apr-09 5:39 
GeneralRe: Socket Connection Shutdown and Close Pin
Colin Angus Mackay16-Apr-09 5:48
Colin Angus Mackay16-Apr-09 5:48 
AnswerRe: Socket Connection Shutdown and Close Pin
kikeman16-Apr-09 5:55
kikeman16-Apr-09 5:55 
QuestionTask Scheduler Pin
BlitzPackage15-Apr-09 11:40
BlitzPackage15-Apr-09 11:40 
AnswerRe: Task Scheduler Pin
Pete O'Hanlon15-Apr-09 11:45
mvePete O'Hanlon15-Apr-09 11:45 
GeneralRe: Task Scheduler Pin
BlitzPackage15-Apr-09 15:59
BlitzPackage15-Apr-09 15:59 
AnswerRe: Task Scheduler Pin
Rolando CC15-Apr-09 12:52
professionalRolando CC15-Apr-09 12:52 
GeneralRe: Task Scheduler Pin
BlitzPackage15-Apr-09 15:58
BlitzPackage15-Apr-09 15:58 
AnswerRe: Task Scheduler Pin
Giorgi Dalakishvili15-Apr-09 19:45
mentorGiorgi Dalakishvili15-Apr-09 19:45 
QuestionVS2008 Startup, Environment, Options Dialog Box missing Pin
Neville Franks15-Apr-09 10:51
Neville Franks15-Apr-09 10:51 
AnswerRe: VS2008 Startup, Environment, Options Dialog Box missing Pin
Neville Franks15-Apr-09 11:00
Neville Franks15-Apr-09 11:00 
JokeWhat are trees doing in your pants? Pin
Naruki15-Apr-09 15:18
Naruki15-Apr-09 15:18 
GeneralRe: What are trees doing in your pants? Pin
Neville Franks15-Apr-09 16:26
Neville Franks15-Apr-09 16:26 
JokeRe: What are trees doing in your pants? Pin
Naruki15-Apr-09 16:54
Naruki15-Apr-09 16:54 
GeneralRe: What are trees doing in your pants? Pin
Neville Franks15-Apr-09 18:00
Neville Franks15-Apr-09 18:00 
QuestionProgress while reading a file Pin
nike_arh15-Apr-09 10:38
nike_arh15-Apr-09 10:38 
AnswerRe: Progress while reading a file Pin
amtadhani15-Apr-09 10:45
amtadhani15-Apr-09 10:45 

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.