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

C#

 
AnswerRe: Receiving Data Asynchronously on Socket Class Pin
BobJanova3-Oct-11 23:10
BobJanova3-Oct-11 23:10 
GeneralRe: Receiving Data Asynchronously on Socket Class Pin
Richard Andrew x644-Oct-11 11:11
professionalRichard Andrew x644-Oct-11 11:11 
GeneralRe: Receiving Data Asynchronously on Socket Class Pin
BobJanova4-Oct-11 22:55
BobJanova4-Oct-11 22:55 
GeneralRe: Receiving Data Asynchronously on Socket Class Pin
jschell5-Oct-11 9:01
jschell5-Oct-11 9:01 
AnswerRe: Receiving Data Asynchronously on Socket Class Pin
jschell4-Oct-11 11:07
jschell4-Oct-11 11:07 
GeneralRe: Receiving Data Asynchronously on Socket Class Pin
Richard Andrew x644-Oct-11 11:12
professionalRichard Andrew x644-Oct-11 11:12 
GeneralRe: Receiving Data Asynchronously on Socket Class Pin
jschell5-Oct-11 9:04
jschell5-Oct-11 9:04 
QuestionRemoving duplicate object instances? Pin
R4jlu3-Oct-11 2:41
R4jlu3-Oct-11 2:41 
Hey. Sorry if i have not quite got the lingo but here goes.

So i have declared an instance ('finalCellCompiler') of the CompileFinalCell class globally (for access across the whole form) and upon clicking the twoDDisplay button on the form finalCellCompiler is initialised with the *new keyword.

The CompileFinalCell class features the IDisposable wrapper and a dispose method to dispose of the object. A seperate reset button calls the clear method to get rid of the finalCellCompiler object.

The issue i have is that after calling the reset method and subsequently the twoDDisplay i get two instances of the finalCellCompiler as when i click a third button 'depositNext' (which is handled inside the CompileFinalCell class) the messageBox is call twice from each instance.

I am trying to figure out a way of replacing the original instance without creating major modifications to my code.

Any help would be greatly appreciated. Thanks.

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 Clear()
    {
        if (finalCellCompiler != null)
        {
            finalCellCompiler.Dispose();
            finalCellCompiler = null;
        }
        GC.Collect();
    }
}

class CompileFinalCell : IDisposable
{
    //FIELDS
    Form1 _form1Data;             // Reference copy of the form1Data

    //CONTRUCTOR
    public CompileFinalCell(Form1 originalFormData,
    FibrePositionGenerator fibreData, SizeF outerCell,
    ForceDirectedAlgorithm beamForce,
        ForceDirectedAlgorithm shellForce)
    {
        //Assign field variables by reference
        _form1Data = originalFormData;

        //Create event handlers
        _form1Data.depositNext.Click += new
        EventHandler(depositNext_Click);
    }

    private void depositNext_Click(object sender, EventArgs e)
    { MessageBox.Show("Button clicked"); }

    public void Dispose()
    { GC.SuppressFinalize(this); }
}

AnswerRe: Removing duplicate object instances? Pin
Pete O'Hanlon3-Oct-11 3:06
mvePete O'Hanlon3-Oct-11 3:06 
GeneralRe: Removing duplicate object instances? Pin
R4jlu3-Oct-11 3:26
R4jlu3-Oct-11 3:26 
AnswerRe: Removing duplicate object instances? Pin
Luc Pattyn3-Oct-11 3:51
sitebuilderLuc Pattyn3-Oct-11 3:51 
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 
QuestionWinForm Management Pin
Arjun Thadani2-Oct-11 22:17
Arjun Thadani2-Oct-11 22:17 
AnswerRe: WinForm Management PinPopular
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 

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.