sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

golang dynamics setText() not work #204

Closed maojindao55 closed 5 years ago

maojindao55 commented 5 years ago

such my code : two steps not work!

func main()
{
root, _ := w.GetRootElement()
updProcessTip(root, 'handle process ready!')  //not work
handleProc(root)
updProcessTip(root, 'handle process done!')  // worked!
}
func updProcessTip(root *sciter.Element, text string) {
    dv, _ := root.SelectFirst("#process")
    dv.SetText(text)
}
func handleProc(root *sciter.Element) {
       updProcessTip(root, 'handle process starting!') //not work

}
c-smile commented 5 years ago

It appears as your handleProc(root) is a synchronous routine. And so, while running, it blocks any UI updates.

Instead you should move time consuming processing in separate threads (goroutines) :

func main()
{
  root, _ := w.GetRootElement()
  updProcessTip(root, 'handle process ready!')  //not work
  go Processing()
}

func Processing() { // that shall be run as a thread
  handleProc(root)
  updProcessTip(root, 'handle process done!')  // worked!
}

Note that is just a sketch, I am not a Go programmer.

maojindao55 commented 5 years ago

thx It worked fined