Simple task: make a while that update's status.label value,
but it is not possible to implement via threads, because function cannot be gcsafe when it calls global status to update its value and it is not possible to transmit status.value via channel because of target while app.mainLoop() cannot be extended, to inject channel catcher and it is not possible to start app.mainLoop() as separated thread, because it is not gcsafe too.
So idk how to implement it.
import
os,
resource/resource,
wNim
var app = App()
var frame = Frame(title="wNim while test", style=wDefaultFrameStyle or wModalFrame)
frame.size = (200, 100)
var panel = Panel(frame)
panel.margin = 10
var status = StaticText(panel, label="...")
status.label = "null"
frame.center()
frame.show()
proc mywhile() =
var i = 0
while(true):
status.label = $i
echo i
i = i + 1
os.sleep(1000)
status_ch.open()
var th2: Thread[void]
createThread(th2, mywhile)
app.mainLoop()
th2.joinThread()
You can use SendMessage to communicate between threads. For example:
import os, threadpool
import wNim/[wApp, wFrame, wPanel, wStaticText]
import winim/lean
const wEvent_SetLabel = wEvent_App + 1
var app = App()
var frame = Frame(size=(200, 100))
var panel = Panel(frame)
panel.margin = 10
var status = StaticText(panel)
frame.center()
frame.show()
status.wEvent_SetLabel do (event: wEvent):
status.label = $event.wParam
status.fit
proc mywhile(hwnd: HWND) {.thread.} =
var i = 0
while(true):
SendMessage(hwnd, wEvent_SetLabel, WPARAM i, 0)
i.inc
os.sleep(1000)
spawn mywhile(status.handle)
app.mainLoop()
Here I use threadpool and spawn. To use createThread is ok.