2016-07-24 7 views
0

私はUbuntu 14.04とRaspian (Raspberry Pi 2B)の両方でシステムコール "スリープ"を使用しようとしました。 5秒。しかし、驚くべきことに、Delay内のシステムコール "sleep"の前にあるすべてのコードは、実行時にはまったく実行されません。システムコールスリープが正しく動作しない

using System; 
using Gtk; 
using Mono.Unix.Native;    

public partial class MainWindow: Gtk.Window 
{ 
    public MainWindow() : base (Gtk.WindowType.Toplevel) 
    { 
     Build(); 

     entry1.Alignment = 0.5f; 

     // This code is not executed: 
     double result = Math.Pow (2.0, 2.0); 
     entry1.Text = result.ToString(); 
     // End of code not executed 

     // Code executed: 
     Delay (5); 
     entry1.Text = "Button-A"; 
    } 

    protected void OnDeleteEvent (object sender, DeleteEventArgs a) 
    { 
     Application.Quit(); 
     a.RetVal = true; 
    } 

    private Int16 Delay (UInt32 value) 
    { 
     Mono.Unix.Native.Syscall.sleep (value);  
     return 0; 
    } 
} 

私はLinuxの基本的なことを誤解していますか、コンパイラエラーに直面していますか?件名へのヒントをありがとう!

答えて

0

メインUIスレッドでブロックしています。

システムexecを使用して実行をブロック/遅延する代わりに、代わりにTask.Delayを使用してください。

await Task.Delay(5000); 
関連する問題