dontpanic92 / wxGo

Golang wxWidgets Wrapper
Other
403 stars 51 forks source link

How to run long function without blocking UI, but updating it? #35

Closed spieglt closed 6 years ago

spieglt commented 6 years ago

First of all, thank you for this project. It's the only viable cross-platform GUI for Go I've found. I've been using it in my project (https://github.com/spieglt/flyingcarpet/tree/wxgo) the last few days and am confused on a couple things. How should I start a long-running function from my main frame without blocking the frame? And how should I allow that function to update the frame? Right now I have the function running in a goroutine, and have put the UI bits I need to update in globals, but I know that's not the right way to do it and I think it's causing stability issues.

I don't see how to do the threading/event model like you would do in C++ because we're in Go. I also couldn't find any parallel cases in the examples. Thanks for any help you can provide!

dontpanic92 commented 6 years ago

Hi, please refer the threadevent example https://github.com/dontpanic92/wxGo/blob/master/examples/src/threadevent/main.go

This is a simple demo that shows how to use goroutine and how to communicate between goroutines.

spieglt commented 6 years ago

Ah! Thank you, don't know how I missed that.