magicm
02-19-2009, 02:54 PM
I've run into this weird issue with a script I'm working on where using dotNet.addEventHandler doesn't do anything when invoked from inside a ca's event.
Below is a simplified script to illustrate what I'm trying to accomplish. In the original script the on TestParam set val actually calls a function that creates a dotNetObject (unless it already exists) and attaches several event handlers. However, to find out what was going wrong I wrote this simple test script:
fn Tmr_Tick =
(
print "Tick!"
Tmr.Stop()
)
TestCa = attributes "TestCa"
(
parameters params
(
TestParam type:#integer
on TestParam set val do
(
Tmr = dotNetObject "System.Windows.Forms.Timer"
dotNet.addEventHandler Tmr "Tick" Tmr_Tick
Tmr.Interval = 100
Tmr.Start()
)
)
)
TestObj = box()
custAttributes.add TestObj TestCa
After running the above script, enter line by line in the listener:
Tmr
undefined
TestObj.TestParam = 1
1
no "Tick" ?
Tmr
dotNetObject:System.Windows.Forms.Timer
Tmr.Enabled
true
So at this point the timer is created and is running, but the Tmr_Tick function is never called.
Adding the event manually in the listener after this:
dotNet.addEventHandler Tmr "Tick" Tmr_Tick
OK
"Tick!"
Any ideas would be very much appreciated!
Thanks,
Martijn
Below is a simplified script to illustrate what I'm trying to accomplish. In the original script the on TestParam set val actually calls a function that creates a dotNetObject (unless it already exists) and attaches several event handlers. However, to find out what was going wrong I wrote this simple test script:
fn Tmr_Tick =
(
print "Tick!"
Tmr.Stop()
)
TestCa = attributes "TestCa"
(
parameters params
(
TestParam type:#integer
on TestParam set val do
(
Tmr = dotNetObject "System.Windows.Forms.Timer"
dotNet.addEventHandler Tmr "Tick" Tmr_Tick
Tmr.Interval = 100
Tmr.Start()
)
)
)
TestObj = box()
custAttributes.add TestObj TestCa
After running the above script, enter line by line in the listener:
Tmr
undefined
TestObj.TestParam = 1
1
no "Tick" ?
Tmr
dotNetObject:System.Windows.Forms.Timer
Tmr.Enabled
true
So at this point the timer is created and is running, but the Tmr_Tick function is never called.
Adding the event manually in the listener after this:
dotNet.addEventHandler Tmr "Tick" Tmr_Tick
OK
"Tick!"
Any ideas would be very much appreciated!
Thanks,
Martijn
