algorithmic modeling for Rhino
Hey all,
I want to be able to cancel one of my time consuming scripts by hitting Esc.
I know its possible in a visual studio environment by using a background worker (which I have not tried) but if anyone has advice that is simpler I would really like a way to stop my super heavy components without crashing Rhino & Grasshopper
Thanks!
Tags:
Hi Andy,
So you should definitely use a Background worker or Asynchrone/Parallel Threading(depends on what you're doing).
You can then use an eventhandler to check for esc key like this:
private void Form_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Escape) {
bw.CancelAsync();
}
}
If you're not using these Threading techniques Rhino & GH will freeze until your algorithm finishes calculating. The effort of Parallel Threading is, you can use multiple CPU's instead of just one (like GH).
Hope this gives you some ideas
FF
Hi Andy,
you can have a look at a basic implementation of the BackgroundWorker here (see at the bottom). The code attached is implemented in a C# component, but you can easily use the same pattern within a compiled component. As Florian suggested you can make the worker cancellable by setting the property WorkerSupportsCancellation to true, like so:
worker.WorkerSupportsCancellation = true;
and then providing the proper event handler.
Cheers,
r
GH_Document.IsEscapeKeyDown()
this is a static method that you can call. If the method returns True, then abort your script and call GH_Document.RequestAbortSolution()
--
David Rutten
david@mcneel.com
Tirol, Austria
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson.
Powered by