Grasshopper

algorithmic modeling for Rhino

Grasshopper + rhino plugin + Sql-listener -> what's the correct C# design pattern?

Hi all,

We're writing a rhino-plugin to open/run/close a .ghx files in an open instance of rhino/grasshopper. I would like the plugin to get notified if a new item is added in the queue (a mssql database running on the same local machine). 

I came up with a solution but i'm looking for a better code pattern since this one has the Rhino+Grasshopper UI locked in the RhinoMainWindow thread. (since rhino is not threadsafe) 

Current Solution: 

The RhinoPlugin main thread waits for an 'EventWaitHandle' from a seperate thread that gets notified through an SqlDependency. If it receives the event it opens the .ghx file and performs some actions. After it's done it just starts a new SqlDependency. The beauty is that since Rhino is single-threaded you don't run into problems since you just wait. So you can simply stear the rhino/gh instances to do whatever you like. 

The downside is the UI is completely locked during the waiting. 

Alternative ideas: 

- use a windows.forms.timer (single threaded) to poll the database with a normal query every 500ms. This probably won't lock the UI but can be 500ms slower plus the extra query-overload. 

- ? 

I'm looking forward to any ideas/suggestions/experiences. All thoughts are appreciated! 

cheers,

Elco

Views: 996

Replies to This Discussion

@David, 

Hi David, do you have any suggestions to this topic? 

thx, 

Elco & Jan

Delft

Once you get the event, why not invoke a method on the Rhino main UI thread which starts your Rh+GH logic?

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David, 

Yes i tried that, but i think i invoked on the wrong part or something since GH threw me a very undefined error that it couldn't open a file. I guess it had to do with threading. 

Is this the correct way to invoke a method on rhino's main thread?

if(RhinoApp.MainApplicationWindow.InvokeRequired)
{
     RhinoApp.MainApplicationWindow.Invoke(MyDelegateMethod);
}

thx,

Elco

Hi David, 

The above worked out. I just had to make sure all grasshopper related instances were inside the scope and thread of MyDelegateMethods. 

thanks for your hint. 

have a nice day, 

Elco

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service