I am working on a python script that is animated by positioning a System.Windows.Forms.TrackBar()
The script moves several rhino object to various positions depending on the position of the TrackBar. My current script has all it functions on the same main thread. Whenever the System.Windows.Forms.TrackBar.ValueChanged() event is triggered it will run all the way whatever code is called by the event. This method works fine when doing simple operations like print self.TrackBar.Value. However this becomes a problem when a more complicated script is called by the event, for example when the user is “scrubbing” across the TrackBar. In this situation the TrackBar.Value may have changed from 1 to 100 in the space of 1 second in increments of one. When Rhino is unable to keep up with the change of the TrackBar, Rhino inevitably crashes.
I have a general idea of what I need to do but as of yet I have been unsuccessful in implementing a working situation.
I feel like a viable solution to this problem would having the System.Windows.Forms.TrackBar.ValueChanged() event begin a timer on a separate thread removed from the main script thread.
This would allow the script to restart the timer every time the event is called, then if the timer reaches, say .1 seconds in the same location, then the objects will be moved in Rhino to the current position. This will hopefully eliminate, Rhino crashes from the object move being called too quickly for Rhino to keep up with.
If anyone has any advise on how this could be done or could point me toward a tutorial that covers this I would be most appreciative,