* Conduite.cs: Amelioration de la boucle (precision du timing)
Gestion simple des erreurs dans la boucle * Main.cs: Gestion des erreurs de l'interface * Info.cs: les infos persistent 5s au lieu de 3
This commit is contained in:
parent
aa3d405b6c
commit
afc21dccf0
3 changed files with 48 additions and 11 deletions
|
|
@ -177,19 +177,36 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// On utilise un thread qui boucle au lieu d'un timer.
|
||||
// C'est moins précis, mais ca consomme beaucoup moins de ressources
|
||||
// C'est un peu moins précis, mais ca consomme beaucoup moins de ressources
|
||||
|
||||
|
||||
const int LOOPTIME = 10;
|
||||
|
||||
void ThreadLoop ()
|
||||
{
|
||||
Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
|
||||
TimeSpan delay = TimeSpan.FromMilliseconds(10);
|
||||
TimeSpan sleeptime; int i=0;
|
||||
DateTime next;
|
||||
|
||||
while (running) {
|
||||
|
||||
try{
|
||||
Tick();
|
||||
sleeptime = delay.Subtract(DateTime.Now - dernierTick);
|
||||
if(sleeptime > TimeSpan.Zero)
|
||||
Thread.Sleep(sleeptime);
|
||||
}
|
||||
catch (Exception ex) // Gestion d'erreurs ... au cas ou ... on affiche et on continue
|
||||
{
|
||||
Info.Publish(ex.ToString());
|
||||
}
|
||||
|
||||
next = dernierTick.AddMilliseconds (LOOPTIME);
|
||||
while (DateTime.Now< next) Thread.Sleep(1);
|
||||
|
||||
// Version plus précise, si besoin :
|
||||
// next = dernierTick.AddMilliseconds (LOOPTIME-1);
|
||||
// while (DateTime.Now< next) Thread.Sleep(1);
|
||||
// next = dernierTick.AddMilliseconds (LOOPTIME);
|
||||
// while (DateTime.Now<next) Thread.Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +218,7 @@ namespace DMX2
|
|||
|
||||
if (!Pause) {
|
||||
|
||||
if (deltaT > TimeSpan.FromMilliseconds (12))
|
||||
// if (deltaT > TimeSpan.FromMilliseconds (LOOPTIME+2))
|
||||
Info.Publish(string.Format ("{0}", deltaT));
|
||||
|
||||
lock (this) {
|
||||
|
|
@ -239,10 +256,9 @@ namespace DMX2
|
|||
|
||||
EventManager.ProcessEvents();
|
||||
}
|
||||
// Cette fonction retourne quasi immédiatement, même si il y'a beaucoup a faire sur l'affichage
|
||||
}
|
||||
|
||||
|
||||
// Cette fonction retourne quasi immédiatement, même si il y'a beaucoup a faire sur l'affichage
|
||||
if(tickTime - derniereMaj > TimeSpan.FromMilliseconds(50)){
|
||||
MainWindow.Win.ScheduleUpdate();
|
||||
derniereMaj = DateTime.Now;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace DMX2
|
|||
static string lastinfo = string.Empty;
|
||||
static public void Publish(string info)
|
||||
{
|
||||
last = DateTime.Now.AddSeconds(3);
|
||||
last = DateTime.Now.AddSeconds(5);
|
||||
lastinfo = info;
|
||||
}
|
||||
static public string GetInfo(){
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ namespace DMX2
|
|||
if(fullscreen) win.ToggleFullscreen();
|
||||
if(aguibtn) win.AfficheBoutonACGUI();
|
||||
|
||||
// Gestion des erreurs non traitées dans l'interface
|
||||
GLib.ExceptionManager.UnhandledException += HandleUnhandledException;
|
||||
|
||||
// Lancement
|
||||
win.Show ();
|
||||
Application.Run ();
|
||||
|
|
@ -61,5 +64,23 @@ namespace DMX2
|
|||
Conduite.Courante.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleUnhandledException (GLib.UnhandledExceptionArgs args)
|
||||
{
|
||||
|
||||
// En cas d'erreur non traitée : on affiche et on demande ...
|
||||
var dlg = new Dialog ("Erreur !", null, DialogFlags.Modal);
|
||||
|
||||
dlg.AddButton ("Continuer ..." , ResponseType.Cancel ).GrabDefault();
|
||||
dlg.AddButton ("Fermer l'application" , ResponseType.Close );
|
||||
|
||||
dlg.VBox.Add (new Label (args.ExceptionObject.ToString()));
|
||||
dlg.VBox.ShowAll ();
|
||||
|
||||
// Si l'utilisateur a clique sur le bon bouton, on continue comme si de rien n'etait...
|
||||
args.ExitApplication= (ResponseType)dlg.Run() == ResponseType.Close ;
|
||||
dlg.Destroy();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue