Click here to Skip to main content
15,896,393 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to check operating system in c#..? Pin
Pete O'Hanlon20-May-10 3:59
mvePete O'Hanlon20-May-10 3:59 
GeneralRe: how to check operating system in c#..? Pin
Dave Kreskowiak20-May-10 6:35
mveDave Kreskowiak20-May-10 6:35 
GeneralRe: how to check operating system in c#..? Pin
Johnny J.20-May-10 21:01
professionalJohnny J.20-May-10 21:01 
GeneralRe: how to check operating system in c#..? Pin
Dave Kreskowiak21-May-10 1:45
mveDave Kreskowiak21-May-10 1:45 
AnswerRe: how to check operating system in c#..? Pin
canangirgin20-May-10 4:41
canangirgin20-May-10 4:41 
QuestionDisposing of object used in a UserControl... Pin
Shy Agam19-May-10 21:40
Shy Agam19-May-10 21:40 
AnswerRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon19-May-10 22:11
mvePete O'Hanlon19-May-10 22:11 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn20-May-10 3:20
sitebuilderLuc Pattyn20-May-10 3:20 
Hi Pete,

I always have been, and still am, struggling with this question. Here is a simple example:

I create a UserControl that holds a PictureBox;
I create a modal Form holding two such UserControls and some Buttons

Initially the Form loads one image and shows it in both UC.

then:

scenario 1: I press a button and another image gets loaded in one of the UCs (the original image remains in use in the other UC)
scenario 2: I press another button and one UserControl should vanish (the image remains in use in the other UC)
scenario 3: I press yet another button, it closes the Form (the image is no longer referenced).

So who should be calling Image.Dispose()?
It can't be the UC, as it does not "own" the image.
It shouldn't be the Form, as it will be very vulnerable as soon as the use cases get a bit complex.
So we need some pattern here that automates/hides the problem.

FWIW: the problem vanishes if one never assigns the same image to different UCs, which implies each UC shows a different instance of Image (possibly showing the same thing though), but I want to avoid loading the same image twice if I can reliably do so.

And I don't see how a WeakReference will help me; I know how to use them to possibly keep an object alive, as in a user-created cache. However here the PictureBoxes want to be sure they have the image at hand that they are supposed to show, nothing is supposed to be weak here.

Confused | :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read formatted code with indentation, so please use PRE tags for code snippets.

I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).

GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon20-May-10 3:50
mvePete O'Hanlon20-May-10 3:50 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn20-May-10 4:00
sitebuilderLuc Pattyn20-May-10 4:00 
GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon20-May-10 4:03
mvePete O'Hanlon20-May-10 4:03 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn20-May-10 4:05
sitebuilderLuc Pattyn20-May-10 4:05 
GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon20-May-10 4:17
mvePete O'Hanlon20-May-10 4:17 
GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon21-May-10 11:40
mvePete O'Hanlon21-May-10 11:40 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn21-May-10 11:56
sitebuilderLuc Pattyn21-May-10 11:56 
GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon21-May-10 12:51
mvePete O'Hanlon21-May-10 12:51 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn21-May-10 13:05
sitebuilderLuc Pattyn21-May-10 13:05 
AnswerRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon21-May-10 12:53
mvePete O'Hanlon21-May-10 12:53 
QuestionDistribute values Pin
Bart Van Eyndhoven19-May-10 21:19
Bart Van Eyndhoven19-May-10 21:19 
QuestionMessage Removed Pin
19-May-10 19:30
EthicsGradient19-May-10 19:30 
AnswerRe: How to clear FileSystemWatcher.Path ? [modified] Pin
Johnny J.19-May-10 22:39
professionalJohnny J.19-May-10 22:39 
GeneralMessage Removed Pin
20-May-10 14:33
EthicsGradient20-May-10 14:33 
GeneralRe: How to clear FileSystemWatcher.Path ? Pin
Johnny J.20-May-10 19:55
professionalJohnny J.20-May-10 19:55 
GeneralMessage Removed Pin
21-May-10 3:34
EthicsGradient21-May-10 3:34 
GeneralRe: How to clear FileSystemWatcher.Path ? Pin
Johnny J.21-May-10 3:38
professionalJohnny J.21-May-10 3:38 

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.