Click here to Skip to main content
15,913,944 members
Home / Discussions / C#
   

C#

 
AnswerRe: Assigning Tuple.Create to a Func ? ... an interesting code fragment Pin
Sascha Lefèvre23-Jul-15 12:57
professionalSascha Lefèvre23-Jul-15 12:57 
GeneralRe: Assigning Tuple.Create to a Func ? ... an interesting code fragment Pin
BillWoodruff23-Jul-15 21:52
professionalBillWoodruff23-Jul-15 21:52 
Questionimplement duplex wcf service in iis Pin
tehran135720-Jul-15 2:54
tehran135720-Jul-15 2:54 
AnswerRe: implement duplex wcf service in iis Pin
Pete O'Hanlon20-Jul-15 3:16
mvePete O'Hanlon20-Jul-15 3:16 
AnswerRe: implement duplex wcf service in iis Pin
Eddy Vluggen20-Jul-15 7:47
professionalEddy Vluggen20-Jul-15 7:47 
QuestionDeploy POS.NET files Pin
Jassim Rahma20-Jul-15 2:42
Jassim Rahma20-Jul-15 2:42 
AnswerRe: Deploy POS.NET files Pin
ZurdoDev20-Jul-15 8:47
professionalZurdoDev20-Jul-15 8:47 
QuestionCreating a SELECT Query Based on Textbox Data Pin
John L. DeVito19-Jul-15 4:59
professionalJohn L. DeVito19-Jul-15 4:59 
GeneralRe: Creating a SELECT Query Based on Textbox Data Pin
PIEBALDconsult19-Jul-15 5:06
mvePIEBALDconsult19-Jul-15 5:06 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Wendelius19-Jul-15 5:25
mentorWendelius19-Jul-15 5:25 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Dave Kreskowiak19-Jul-15 6:29
mveDave Kreskowiak19-Jul-15 6:29 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
F-ES Sitecore19-Jul-15 22:29
professionalF-ES Sitecore19-Jul-15 22:29 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Richard Deeming20-Jul-15 6:58
mveRichard Deeming20-Jul-15 6:58 
Questionan unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 4:05
professionalBillWoodruff19-Jul-15 4:05 
AnswerRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Alan N19-Jul-15 9:44
Alan N19-Jul-15 9:44 
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 11:46
professionalBillWoodruff19-Jul-15 11:46 
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Member 1113646119-Jul-15 10:01
Member 1113646119-Jul-15 10:01 
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 11:49
professionalBillWoodruff19-Jul-15 11:49 
AnswerRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Richard Deeming20-Jul-15 6:43
mveRichard Deeming20-Jul-15 6:43 
I suspect the key is to look at what the compiler's doing behind the scenes.

Your anonymous LocationChanged handler closes over three parameters and an instance field, so the compiler will generate something like this:
C#
private sealed class SetActionClosure
{
    public Form1 @this;
    public Control bControl;
    public Control dControl;
    public SomeEnum someenum;
    
    public void AnonymousLocationChangedHandler(object sender, EventArgs e)
    {
        @this.EnumToAction[someenum](bControl, dControl);
    }
}

private void SetActive(Control bControl /* == this */, Control dControl /* == f2 */, SomeEnum someenum)
{
    SetActionClosure closure = new SetActionClosure();
    closure.@this = this;
    closure.bControl = bControl; // == this
    closure.dControl = dControl; // == f2
    closure.someenum = someenum;
    
    bControl /* == this */ .LocationChanged += closure.AnonymousLocationChangedHandler;
    ...
}

The instance of the closure class will remain alive as long as the event handler still has a reference to it - ie: until you unsubscribe the handler, or close the Form1 instance.

That closure class instance has a reference to the Form2 instance "f2". That Form2 instance will remain in alive for as long as the closure class instance remains alive.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionApplication is Crashing Pin
Jassim Rahma19-Jul-15 1:10
Jassim Rahma19-Jul-15 1:10 
AnswerRe: Application is Crashing Pin
OriginalGriff19-Jul-15 1:36
mveOriginalGriff19-Jul-15 1:36 
AnswerRe: Application is Crashing Pin
Dave Kreskowiak19-Jul-15 3:54
mveDave Kreskowiak19-Jul-15 3:54 
QuestionHow to get google place predictions with latitude, longitude and address based on Textbox entry in c# Pin
sr15918-Jul-15 19:05
sr15918-Jul-15 19:05 
AnswerRe: How to get google place predictions with latitude, longitude and address based on Textbox entry in c# Pin
OriginalGriff18-Jul-15 20:17
mveOriginalGriff18-Jul-15 20:17 
QuestionCar tracker Pin
lolinga218-Jul-15 8:58
lolinga218-Jul-15 8:58 

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.