i am writing a video capture component in C#
this is the code:
when i use the component,it works and update every frame ,looks like animation…it fine
but after running several minute(1 or 2 minitues),gh will show a dialog:
i translate the chinese into english in the picture…
how to fix that problem(the problem I guess, may because the events(“NewFrame”) is on a non-UI thread,and the time in ScheduleSolution(time,callater) is “1”,may be not so good),and how to debug that(because it cannot use breakpoint in visual studio,i tried,but failed…)
Thank you very much!
Seems to be a typical problem of concurrency. You could implement a lock when modifing members running on the ui thread, or you simply replace the image from the ui thread:
The last block can be simplified by Grasshopper.Instances.ActiveCanvas.BeginInvoke((cimage) => UpdateSetData(cimage));
You of course need to change the UpdateSetData to passing the “cimage” as argument, which then sets the component member “image”. ( I personally use underscore to distinguish between private class member variables and local variables (= _image and image, is better then image and cimage). But you get the point.
Did this solve the problem? Enable breakpoints must be possible, don’t remeber, but in this case it won’t help, since problemes due to concurrency are hard to debug by breakpoints anyway…
Thank you Tom,i add a lock…
but it also has the same problem(show gh breakpoint dialog…)
Don’t know. Its actually a bit hard without having the full code…
Anyway, you can set breakpoints, by disable COFF in the Grasshopper DeveloperSettings for you gha file. You’ll need to excute Rhino, and in VS->Debug->AttachToProcess (I’m using German, so it maybe is named differently)