Structs and dotnet event handlers

This is driving me insane.

I’ve broken my code into a bunch of structs. Makes things a lot cleaner for me, easier to keep organized.

I’ve also moved all my UI work into C# and dlls.

The issue I’m having is that I can’t get the dotnet event handlers to fire off. I get no errors, mind you. Just no functionality.

I’ve tried:

dotNet.addEventHandler (::CharacterConverter.Dialog.Controls.Find "closeButton" true)[1] "Click" ::CharacterConverter.Hide

dotNet.addEventHandler Dialog.closeButton "Click" this.Hide

and

dotNet.addEventHandler this.Dialog.closeButton "Click" this.Hide

…and they don’t work. However, as soon as I type:

button = CharacterConverter.Dialog.CloseButton
fn close = (format "Closing dialog.
"; CharacterConverter.Hide())
dotNet.addEventHandler button "Click" close

into the listener and click the button on the form, it works… What am I doing wrong?

Nevermind. For some reason, the damned thing just didn’t want to work on a specific instance of the struct. As soon as I changed:

dotNet.addEventHandler Dialog.closeButton "Click" this.Hide

to

dotNet.addEventHandler Dialog.closeButton "Click" Hide

and made the Hide function specify which instance to operate on (there’s only ever one instance anyway), it worked.

There goes several hours of my day.

Also keep in mind garbage collection, for future reference:

dotNet.setLifetimeControl {<dotNetObject> | <dotNetClass>} {#mxs | #dotnet}