Click here to Skip to main content
15,908,775 members
Home / Discussions / C#
   

C#

 
GeneralRe: Removing duplicate object instances? Pin
R4jlu3-Oct-11 4:13
R4jlu3-Oct-11 4:13 
AnswerRe: Removing duplicate object instances? Pin
Luc Pattyn3-Oct-11 4:48
sitebuilderLuc Pattyn3-Oct-11 4:48 
GeneralRe: Removing duplicate object instances? Pin
Pete O'Hanlon3-Oct-11 5:04
mvePete O'Hanlon3-Oct-11 5:04 
AnswerRe: Removing duplicate object instances? Pin
Luc Pattyn3-Oct-11 5:12
sitebuilderLuc Pattyn3-Oct-11 5:12 
GeneralRe: Removing duplicate object instances? Pin
BobJanova3-Oct-11 5:24
BobJanova3-Oct-11 5:24 
GeneralRe: Removing duplicate object instances? Pin
R4jlu3-Oct-11 5:58
R4jlu3-Oct-11 5:58 
GeneralRe: Removing duplicate object instances? Pin
Pete O'Hanlon3-Oct-11 6:03
mvePete O'Hanlon3-Oct-11 6:03 
AnswerRe: Removing duplicate object instances? Pin
BobJanova3-Oct-11 4:23
BobJanova3-Oct-11 4:23 
As has been hinted at above, you've got the dependency backwards with that event handler. If a CompileFinalCell is a temporary thing owned by the form, if possible the calls should all go from form to compiler:

    public partial class Form1 : Form
    {
        //FIELD VARIABLES
        private CompileFinalCell finalCellCompiler;
 
        private void twoDDisplay_Click(object sender, EventArgs e)
        { 
         finalCellCompiler = new CompileFinalCell(this,      
         fibrePositionGenerator, unitCellData.outerCellSize, 
         finalBeamForce, finalShellForce); 
        }
 
        private void DepositNextHandler(object sender, EventArgs e) { 
            if(finalCellCompiler != null) finalCellCompiler.DepositNext();
        }

        private void Clear()
        {
            // Let the GC handle this itself
            if (finalCellCompiler != null)
            {
                finalCellCompiler = null;
            }               
        }
    }
 
    class CompileFinalCell
    {
        //CONTRUCTOR
        public CompileFinalCell(FibrePositionGenerator fibreData, SizeF outerCell,  
            ForceDirectedAlgorithm beamForce,
            ForceDirectedAlgorithm shellForce)
        {
            // I guess you do something with these parameters ...
        }
 
        public void DepositNext()
        { MessageBox.Show("Button clicked"); }
    }


You don't need to implement IDisposable on something which has only managed references, as a general rule (it's designed for releasing system level things like file handles, graphics objects, fonts etc which are limited in number and it's important that you clean up quickly).

Edit: oh yes, don't forget to hook up that button click handler in the form's designer.

This also has the (major) benefit that the final cell compiler is now independent of the UI, i.e. you could create it in a background thread, from network input, as a scheduled service etc without having to change the code.

If the compiler needs to communicate back the other way, you should give it events which the form can then hook onto.
QuestionWinForm Management Pin
Arjun Thadani2-Oct-11 22:17
Arjun Thadani2-Oct-11 22:17 
AnswerRe: WinForm Management Pin
Shameel2-Oct-11 22:31
professionalShameel2-Oct-11 22:31 
GeneralRe: WinForm Management Pin
Arjun Thadani2-Oct-11 23:40
Arjun Thadani2-Oct-11 23:40 
GeneralRe: WinForm Management Pin
BobJanova3-Oct-11 1:05
BobJanova3-Oct-11 1:05 
QuestionHow do you get an Idle Message in a UserControl class in C#? Pin
Xarzu2-Oct-11 18:05
Xarzu2-Oct-11 18:05 
Questionget Url of a frame from browser Pin
moums2-Oct-11 8:46
moums2-Oct-11 8:46 
Questioncode for HDD serial number Pin
sokh2-Oct-11 2:41
sokh2-Oct-11 2:41 
AnswerRe: code for HDD serial number Pin
André Kraak2-Oct-11 2:59
André Kraak2-Oct-11 2:59 
AnswerRe: code for HDD serial number Pin
Dave Kreskowiak2-Oct-11 4:57
mveDave Kreskowiak2-Oct-11 4:57 
AnswerRe: code for HDD serial number Pin
Luc Pattyn2-Oct-11 7:00
sitebuilderLuc Pattyn2-Oct-11 7:00 
QuestionIssue with Imultiple result sets Pin
siva45530-Sep-11 21:46
siva45530-Sep-11 21:46 
AnswerRe: Issue with Imultiple result sets Pin
Richard MacCutchan1-Oct-11 2:26
mveRichard MacCutchan1-Oct-11 2:26 
AnswerRe: Issue with Imultiple result sets Pin
Dave Kreskowiak1-Oct-11 2:48
mveDave Kreskowiak1-Oct-11 2:48 
GeneralRe: Issue with Imultiple result sets Pin
siva4551-Oct-11 18:02
siva4551-Oct-11 18:02 
GeneralRe: Issue with Imultiple result sets Pin
Dave Kreskowiak2-Oct-11 1:56
mveDave Kreskowiak2-Oct-11 1:56 
AnswerRe: Issue with Imultiple result sets Pin
BobJanova2-Oct-11 22:22
BobJanova2-Oct-11 22:22 
QuestionCrystal reports Pin
Neha_Gupta30-Sep-11 20:20
Neha_Gupta30-Sep-11 20:20 

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.