LastExceed
01/25/2020, 8:54 AMIllegalStateException: Not on FX application thread
. How do I deal with this? also why does it only happen when the list isn't empty ?matthjes
01/25/2020, 9:00 AMui
block together with runAsync
? Any view update must be done inside the UI thread, it seems like you're trying to update UI elements outside of it. Please refer to https://edvin.gitbooks.io/tornadofx-guide/part1/3.%20Components.html, chapter "Long running tasks".LastExceed
01/25/2020, 10:14 AMLastExceed
01/25/2020, 10:15 AMimport <http://tornadofx.App|tornadofx.App>
import kotlin.concurrent.thread
fun main() {
launch<MyApp>()
}
class MyApp : App(MyView::class)
class MyView : View("MyTestProgram") {
val myList = observableListOf("banana", "potato")
override val root = form {
listview(myList)
thread {
runBlocking {
MyNetworker.readMessages(myList)
}
}
}
}
object MyNetworker {
private lateinit var socket: Socket
//lets assume we already have an established tcp connection to keep the example short
suspend fun readMessages(myList: ObservableList<String>) {
val readChannel = socket.openReadChannel()
while (true) {
val message = readChannel.readUTF8Line(32)!!
myList.add(message) //exception is thrown here because we're using another thread to modify the ui
}
}
}
i know its garbage in many ways, but it shows what i want to do. what would be the proper way to do it?Arthur
01/25/2020, 11:25 AMLastExceed
01/25/2020, 11:28 AMArthur
01/25/2020, 11:31 AMLastExceed
01/25/2020, 12:04 PM