Notifications
Clear all

[Closed] Dotnet timer differences

ftm = dotnetobject “System.Windows.Forms.Timer”
ttm = dotnetobject “System.Timers.Timer”
ntm = dotnetobject “Timer”

what is the difference?

may there appear conflicts if some are used simultaneously in different scripts? If yes, then how to avoid?

6 Replies
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Just shorter version in terms of writing but control is the same

 lo1

“System.Windows.Forms.Timer” is the same class as “Timer”. Maxscript automatically searches inside “System.Windows.Forms”.

“System.Timers.Timer” is a different beast, and so is “System.Threading.Timer”.

Read about the differences:
http://msdn.microsoft.com/en-us/magazine/cc164015.aspx

Thanks Rotem for this info

(
 	local theTimer -- If its global then it's working from startup
 	fn myfn = 
 	(
 		print "inside function"
 	)
 
 	print "outside function"
 	
 	theTimer = dotNetObject "System.Windows.Forms.Timer"
 	theTimer.interval = 200
 	theTimer.start()
 	fn onTick s a =
 	 (
 		myfn()
 		theTimer.Stop()
 	 )
 	dotnet.addEventHandler theTimer "tick" onTick
 )

I’ve got a very strange situation. Why the timer should be global to work from startup?

 lo1

It doesn’t have to be global, but in order to keep it from being garbage collected, you must:

  • keep a reference to it somewhere, like a struct, rollout, etc.
  • or use dotnet.SetLifetimeControl #dotnet

Thank you, lo! Now it’s working great!