如何从另一个线程设置textview
How to set textview from another thread
我试图从主线程之外的其他线程设置文本视图的文本,所以我在构造函数中写了:
Thread myth = new Thread (new ThreadStart (set_txt));
myth.Start ();
当然 set_txt 是一个包含
的方法
textview1.Buffer.Text = "Whatever";
问题是,当我 运行 代码大多数时候它停止并给出错误:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
我该怎么办??
您需要从 GUI 线程更新 GTK# 文本视图。您可以使用 Gtk.Application.Invoke:
Gtk.Application.Invoke (delegate {
textview1.Buffer.Text = "Whatever";
});
您需要从 UI 线程更新 UI。只需使用 Gtk.Application.Invoke
传递一个 lambda 或委托:
Gtk.Application.Invoke(() => { textview1.Buffer.Text = "Whatever"; });
我试图从主线程之外的其他线程设置文本视图的文本,所以我在构造函数中写了:
Thread myth = new Thread (new ThreadStart (set_txt));
myth.Start ();
当然 set_txt 是一个包含
的方法 textview1.Buffer.Text = "Whatever";
问题是,当我 运行 代码大多数时候它停止并给出错误:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
我该怎么办??
您需要从 GUI 线程更新 GTK# 文本视图。您可以使用 Gtk.Application.Invoke:
Gtk.Application.Invoke (delegate {
textview1.Buffer.Text = "Whatever";
});
您需要从 UI 线程更新 UI。只需使用 Gtk.Application.Invoke
传递一个 lambda 或委托:
Gtk.Application.Invoke(() => { textview1.Buffer.Text = "Whatever"; });