Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to use message box in windows service project. Pin
prasadbuddhika14-May-08 21:04
prasadbuddhika14-May-08 21:04 
GeneralRe: how to use message box in windows service project. Pin
Member 9615-May-08 5:28
Member 9615-May-08 5:28 
Questionthread safe in Dispose method Pin
George_George14-May-08 2:57
George_George14-May-08 2:57 
AnswerRe: thread safe in Dispose method Pin
Christian Graus14-May-08 3:00
protectorChristian Graus14-May-08 3:00 
GeneralRe: thread safe in Dispose method Pin
George_George14-May-08 15:16
George_George14-May-08 15:16 
GeneralRe: thread safe in Dispose method Pin
Peter Josefsson Sweden14-May-08 16:08
Peter Josefsson Sweden14-May-08 16:08 
GeneralRe: thread safe in Dispose method Pin
George_George14-May-08 16:20
George_George14-May-08 16:20 
GeneralRe: thread safe in Dispose method Pin
Peter Josefsson Sweden14-May-08 17:00
Peter Josefsson Sweden14-May-08 17:00 
1. I'll try.

If I remember the recommendations for the IDisposable interface correctly, the requirement that duplicate (but not simultaneous, mind you) calls to Dispose() shouldn't fail is explained with something like this:

MyClass obj = new MyClass();
try
{
    obj.DoSomethingThatCanFail(); // A: we may fail here - obj is not disposed
    obj.Dispose(); // dispose it
    this.DoSomeOtherStuff(); // B: we may fail here - obj could be disposed
}
catch
{
    obj.Dispose(); // make sure obj is disposed
    throw;
}


This code should be considered correct - that is, you shouldn't have to check if things went wrong at A or B in the catch block. Note that obj could potentially be a 2GB image, and the DoSomeOtherStuff() method could also be something extremely memory-hungry. In which case it makes sense to call obj.Dispose() then and there instead of in a finally block.

2. Exactly.

No one but you refers to it and you aren't ever going to use it again. If you can't guarantee those conditions, you're essentially not allowed to Dispose() the object.

3. Yes.

According to Microsofts current recommendations, ObjectDisposedException should be thrown if you try to do anything with an object that is disposed (except calling Dispose() again). But like I said, there's a lot of code out there that just crashes instead. Understandably - it's easy to forget if (disposed) throw new ObjectDisposedException(); in a method or property somewhere.

Which makes it even more important to never use Dispose() unless you're absolutely sure that the object is dead. People who get buried alive don't play nice... Smile | :)

Later,

--
Peter

GeneralRe: thread safe in Dispose method Pin
George_George14-May-08 17:26
George_George14-May-08 17:26 
GeneralRe: thread safe in Dispose method Pin
Peter Josefsson Sweden15-May-08 8:51
Peter Josefsson Sweden15-May-08 8:51 
GeneralRe: thread safe in Dispose method Pin
George_George16-May-08 20:42
George_George16-May-08 20:42 
GeneralRe: thread safe in Dispose method Pin
Peter Josefsson Sweden16-May-08 21:46
Peter Josefsson Sweden16-May-08 21:46 
AnswerRe: thread safe in Dispose method Pin
Peter Josefsson Sweden14-May-08 5:57
Peter Josefsson Sweden14-May-08 5:57 
GeneralRe: thread safe in Dispose method Pin
George_George14-May-08 15:21
George_George14-May-08 15:21 
QuestionDllImport question Pin
matt23lucier14-May-08 2:20
matt23lucier14-May-08 2:20 
AnswerRe: DllImport question Pin
Christian Graus14-May-08 2:38
protectorChristian Graus14-May-08 2:38 
AnswerRe: DllImport question Pin
Dario Solera14-May-08 2:46
Dario Solera14-May-08 2:46 
AnswerRe: DllImport question Pin
carbon_golem14-May-08 4:28
carbon_golem14-May-08 4:28 
AnswerRe: DllImport question Pin
matt23lucier16-May-08 8:16
matt23lucier16-May-08 8:16 
QuestionHow to include visio diagrams in C#.net application Pin
ysunil_7414-May-08 1:33
ysunil_7414-May-08 1:33 
AnswerRe: How to include visio diagrams in C#.net application Pin
Gareth H14-May-08 1:37
Gareth H14-May-08 1:37 
AnswerRe: How to include visio diagrams in C#.net application Pin
Simon P Stevens14-May-08 1:55
Simon P Stevens14-May-08 1:55 
QuestionHow can i obtain a textbox in my webbrowser and pass the text a windows form? Pin
solbyte14-May-08 1:19
solbyte14-May-08 1:19 
AnswerRe: How can i obtain a textbox in my webbrowser and pass the text a windows form? Pin
Christian Graus14-May-08 1:37
protectorChristian Graus14-May-08 1:37 
QuestionCrystal Report Pin
mehrdadc4814-May-08 0:40
mehrdadc4814-May-08 0: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.