Grasshopper

algorithmic modeling for Rhino

Hi all,

Im trying to hack my way through a c# plugin (compiled, not a c# script).

That I'd like to do is to do some processing without blocking grasshopper and when done, update the output variable.

If I put that function on a new thread I couldnt find a way to update the component later correctly.

What is the bast and probably simple way to run just one function that updates a variable (or it can return one, but I thought that a global one is a bit better) in the background without blocking?

Thanks

T

 

        private static String results = String.Empty;

        private static Boolean tDone = false;

        protected override void SolveInstance(IGH_DataAccess DA)

        {

            Listspan class="s3">Line> lines = new Listspan class="s3">Line>();

            if (!DA.GetDataList(0, lines)) { return; }

// can take a lot of time to finish!!

// this updates the global "results" string

            DoSomeHardWork(lines);

            DA.SetDataList(0, results);

            string bb = Convert.ToString(tDone);

            DA.SetData(1, bb);

        }

Views: 1246

Replies to This Discussion

Hi,

C++ is not an issue. Its the C# side on GH.

I used the example above and I change one line to call my remote code.

Runs the first time ok, but then if you change/update the input the plugin wont update (re-run)... at some point after a minute or so, it will run again (not sure if its a GUI trigger, or GH data related)

My comment was an answer to "is calling "thread = null" nice in C# without properly killing the thread?"

My comment was about preventing memory leaks, and that dereferencing a thread is probably not a proper way to kill a thread, especially if you use unmanaged memory (.NET Garbage collection will not free memory used by native code properly. So if you kill a thread you have to clean up after yourself, by creating proper dispose methods.).

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service