系统调用睡眠无法正常工作

时间:2016-07-24 09:43:33

标签: c# mono monodevelop

我试图在Ubuntu 14.04和Raspian (Raspberry Pi 2B)中使用系统调用“sleep”来延迟代码执行,例如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的基本内容或者我是否面临编译错误?感谢您对该主题的任何提示!

1 个答案:

答案 0 :(得分:0)

您在主UI线程上阻止。

而不是使用系统执行程序阻止/延迟执行,而是使用await Task.Delay(5000);

Private Sub Text4_AfterUpdate() 
   DoCmd.ApplyFilter , "[SUMMARY.ORIGIN_CODE]='" & Me![Text4] & "'"
End Sub
相关问题