Grasshopper

algorithmic modeling for Rhino

Hi

I was wondering how the synchronize feature in the GH file-path component works? I would like to be able to do something similar, but not based on file reading/writing. Basically I want to prevent certain components from activating other components unless a specific event occurs. (I know there is something called event handling/listening, but I am not sure how it works) 

Views: 860

Replies to This Discussion

It watches for file system events regarding the files in question. They're a bit cumbersome to deal with because the file system may raise multiple events for a single file change. For example when writing a large file you may get several events during the entire write process. There's also issues with path length and such, it's all terribly 1980's and I don't quite understand why there still isn't something better available.

Also it seems that watching for filesystem events on network drives is exceptionally slow, so only use them for local drives.

The basis of events in .NET are reasonably simple:

  • An event is a special type of field that is part of a class/structure. It can be both static and instance bound.
  • A handler is a method with a specific signature (one that matches the event signature). This method can be private, protected, internal, public, static, non-static, doesn't matter.
  • You register/unregister a handler with an event using the AddHandler and RemoveHandler keywords in VB and the += and -= operators in C#.
  • An event can have any number of handler associated with it and a single handler can 'watch' any number of events, provided it fits the signature for all of them.
  • When the event is 'raised', it basically calls all the handler methods in order.
  • When a handler is associated with an event, the event keeps the handler alive. In other words, Garbage Collector will not collect the object which contains the handler, unless the object containing the event is also collectable. This is one of the more intricate ways in which memory is 'leaked' in .NET applications, it's often difficult to remember to properly unregister handlers and it's hard to find out exactly how many and which handlers are listening to a specific event.

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service