我使用MonoDevelop对显示开始屏幕的应用程序进行编程,并在另一个线程中等待USB记忆棒的输入。
主窗口:
public mainwindow() : base(Gtk.WindowType.TopLevel)
{
Build();
GdkWindow.Fullscreen();
Tast<string> task = WaitForUsbConnection();
task.ContinueWith(_ =>
{
label1.Text = "Usb found - Redirect now.";
Thread.Sleep(2000);
NewWindow window = new NewWindow();
window.show();
this.Close();
}
}
async Task<string> WaitForUsbConnection()
{
while(!MainClass.Usb_there)
{
await Task.Delay(1000);
}
return "found";
}
主要课程的第一个程序:
private static bool usbdevice = false;
public static bool Usb_there
{
get { return usbdevice; }
set { usbdevice = value; }
}
public static void Main(string[] args)
{
Application.Init();
MainWindow window = new MainWindow();
window.show();
Thread usb = new Thread(new ThreadStart(Thread_USB));
usb.Start();
}
public static void Thread_USB()
{
while(true)
{
// .. code to detect usb is working and set bool var to true if usb found
}
}
这就是有时程序有效的方式,有时候不是。你能帮助我吗?或者你能给我正确的方法在单声道和gtk之间切换吗?