[英]Application crashes in XFCE using Mono and GTK#
美好的一天!
我有一個我無法弄清楚自己的問題,而Google這次沒有任何合理的建議。 所以這是最后的希望。
我有一個用C#和WPF編寫的應用程序,我想移植到運行xfce桌面的Debian。 這是使用MonoDevelop和GTK#完成的。 該應用程序非常簡單-連接到區域運輸公司時間表提供者的API,並從附近的車站獲取下一班公交車。
該應用程序現在可以在Linux上運行,並可以更新時間表。 問題是-從啟動開始10到60分鍾后,它隨機崩潰。 沒有錯誤或異常消息。 我在日志中找不到任何內容。 它只是退出(終止)而已。
我有一種直覺,那就是這可能與線程,線程缺失或缺失有關。 以下是MainWindow方法的主要代碼片段。 也許社區可以幫助我,發現我做錯了什么。
謝謝。
private static System.Timers.Timer timer;
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
uiCustomizations();
updateTimetable();
timer = new System.Timers.Timer(180000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(updateTimetable);
timer.Enabled = true;
}
private void updateTimetable (object source = null, ElapsedEventArgs e = null)
{
try {
Log.myLog.AddEntry("Downloading timetable");
ReittiopasConnector ro = new ReittiopasConnector (Parameters.RequestType, Parameters.Stop, Parameters.CurrentTime, Parameters.TimeLimit, Parameters.DepLimit);
Parser data = new Parser (ro.GetXmlStream ());
BusDepartures departures132 = new BusDepartures ();
data.GetBusSchedule (Parameters.Lines [0]);
departures132.SetDepatures = data.ReturnDepartureTimes ();
label_Left_Time1.Text = departures132.Departure;
label_Left_Time2.Text = departures132.FollowingDeparture;
BusDepartures departures503 = new BusDepartures ();
data.GetBusSchedule (Parameters.Lines [1]);
departures503.SetDepatures = data.ReturnDepartureTimes ();
label_Right_Time1.Text = departures503.Departure;
label_Right_Time2.Text = departures503.FollowingDeparture;
//Bus503.DataContext = departures503;
//}));
} catch (Exception ex) {
Log.myLog.AddEntry("Exception: " + ex.Message);
}
}
您需要在同一線程(主線程,也稱為UI線程)中調用GTK / GDK API。 但是,從代碼中看,您似乎正在使用計時器,這意味着您可能正在從計時器已啟動的生成線程中觸摸UI。
因此,您需要使用以下命令包裝對GTK / GDK的調用:
Gtk.Application.Invoke (() => {
label.Text = "Done";
});
更多信息在這里 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.