Grasshopper

algorithmic modeling for Rhino

Hi,

Making my first Component in GH, I ran into a Rhino Crash. It happens at the moment when I close a form for the second time. Basically the component reads a file, displays it in the form, adds something to it and then closes the file and the form. But if in the meanwhile somebody else changed the file, I want to give a warning and close the form. I use the FileSystemWatcher for this. But it also fires of course if I save the file myself. Then I don't want a warning. The error has probably something to do with the FileSystemWatcher, because there is no problem without it . I used the invoke method correctly though. And debugging in VS 2012 vb.net works ok. FileSystemWatcher fires twice, which according to many forums is normal behaviour. But it should only close the form the second time otherwise I get errors reading the name of the author, because the form is not there anymore of course. So I put a counter variable at class level. For checking the error I display a message with the counter value just before closing. Indeed that shows that the closing function is called twice through the invoker delegate. The strange thing is that the second message is shown even when I didn't click OK for the first. Maybe this gives a hint? Something to do with threading I guess. Any body any idea how to close the form in the right way.

Views: 786

Replies to This Discussion

Hi Hans,

sounds like a pretty complicated problem. FileSystemWatcher is indeed difficult to use because it tends to fire multiple events for a single file change. And then of course there's the threading problem and also the Dispose problem as things like FileSystemWatchers and Forms ought to be properly disposed when no longer used.

Wouldn't it make sense to disable the file watcher just before you change the file and then re-enable it afterwards?

Without seeing any code it's really hard to comment on this. But you mention it crashes Rhino, if so there should be a Crash Report window and a file called RhinoDotNetCrash.txt (not 100% sure about the name) on the desktop. If you don't close the Crash Report window you should be able to open this file in Notepad and have a look at the call stack.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service