`add Timer `question

I have the following layout in a script:

renoise.tool():add_keybinding..etc  
  
  
local my_dialog = nil  
  
  
function main()  
  
--GUI created  
  
my_dialog --Now Active and assigned  
  
  
local function view_updater (my_dialog)  
  
--do stuff  
--attempt to remove timer here when GUI closes  
end  
  
  
--timer added here  
renoise.tool():add_timer(view_updater ,100)  
  
end-- of main  

So I start the script with a keybinding, the GUI is created and the timer is added, humming away in the background running the local function view_updater().

However I am trying to remove the timer when the GUI is closed via a conditional within the local function view_updater() :

 if not my_dialog.is_visible then renoise.tool():remove_timer(view_updater) end   

Is there something fundamentally wrong with this? my_dialog seems to be always nil in the local function?

regards

Not to worry I have found a working way. I will post back when I understand it better.