我试图用FXRuby做一个套接字应用程序,一切都很好,直到添加了滚动条,然后应用程序崩溃了。
研究表明,线程是问题所在,但我不知道有什么解决方法。有什么想法吗?
这就是导致问题的线程
def listen()
Thread.new() do
begin
loop{
#gets the message from the socket
msg=@socket.gets()
arr=msg.split(' ')
msg=''
case arr[0]
when '/say'
arr.delete_at(0)
arr.each do |word|
msg+=word + ' '
end
add(msg)
when '/cls'
@textArea.removeText(0, @textArea.length)
when '/stp'
abort
when '/conn'
@socket=EzSSL::Client.new(@ip,arr[1].to_i)
@textArea.removeText(0, @textArea.length)
@textArea.appendText("Connected to port #{arr[1]}")
end
}
rescue
#closes the ruby app on exception
abort
end
end
end
add方法将文本行添加到FXText对象
EzSSL
模块是我创建的一个用openssl进行安全套接字连接的gem,它的工作方式类似于普通的套接字连接。
我是第一次接触Fox-Toolkit和FXRuby,所以非常感谢您的帮助
发布于 2020-08-30 05:55:08
您应该从UI线程更新界面元素,如下所示:
app.runOnUiThread do
@textArea.removeText(0, @textArea.length)
@textArea.appendText("Connected to port #{arr[1]}")
end
https://stackoverflow.com/questions/59254148
复制相似问题