Hi. I'm trying to make a simple gui app that performs functions at the press of
a button. Of course, func is called in the main thread, so gui is freezing. I
tried use the threadpool module, but I do something wrong. From what I
understood, to read the result from thread, I have to use ^, but this causes
freezing gui. When I calls without ^ works well, but how then read return? This
is my simple code, I used nigui.
import strutils
import threadpool
import nigui
import os
app.init()
var window = newWindow("Win")
window.width = 600.scaleToDpi
window.height = 400.scaleToDpi
var container = newLayoutContainer(Layout_Vertical)
window.add(container)
var button = newButton("Start")
var textArea = newTextArea()
container.add(button)
container.add(textArea)
proc doSomthing(time: int): string {.thread.} =
sleep(time)
return "end"
button.onClick = proc(event: ClickEvent) =
var t = spawn doSomthing(5000)
textArea.addLine(^t)
window.show()
app.run()
Run