gpt4 book ai didi

c# - 我怎样才能延迟关机直到 virtualbox 关闭

转载 作者:行者123 更新时间:2023-11-30 18:20:29 35 4
gpt4 key购买 nike

我尝试在本地关闭/重启/注销等之前关闭 vbox。我尝试了一些但没有用。我的代码是:

private void VMStarter_Load(object sender, EventArgs e)
{
...
...
ShutDownHandle.StopShutdown(this.Handle, "Virtual Box is shutting down...");
}

private void tmr_doWork_tick(object sender, EventArgs e)
{
tmr_doWork.Enabled = false;
Controller.closeVM(); //for
while (!ShutDownHandle.ResetShutdown(this.Handle))
{
Thread.Sleep(10);
}
ShutDownHandle.Shutdown();
this.Close();
}

//[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
if (!systemShutdown)
if (m.Msg == (int)EnumClass.WindowsMessageCodes.SM_SHUTTINGDOWN ||
m.Msg == (int)EnumClass.WindowsMessageCodes.WM_ENDSESSION ||
m.Msg == (int)EnumClass.WindowsMessageCodes.WM_QUERYENDSESSION)
{
tmr_Check.Enabled = false;
//Message MyMsg = new Message();
//MyMsg.Msg = (int)EnumClass.WindowsMessageCodes.WM_CANCELMODE;
//base.WndProc(ref MyMsg);
systemShutdown = true;
tmr_doWork.Enabled = true;
return;
}
base.WndProc(ref m);
}

ShutDownHandle 类:包括 StopShutdown 和 ResetShutdown 方法。我使用 ShutdownBlockReasonCreateShutdownBlockReasonDestroy 停止关闭窗口。

public static bool StopShutdown(IntPtr hWdn, string strMessage)
{
try
{
if (ShutdownBlockReasonCreate(hWdn, strMessage))
{
return true;
}
}
catch (Exception ex)
{
Writer.errorWrite(ex);
}
return false;
}

public static bool ResetShutdown(IntPtr hWdn)
{
try
{
return ShutdownBlockReasonDestroy(hWdn);
}
catch (Exception ex)
{
return false;
Writer.errorWrite(ex);
}
return false;
}

我在应用程序运行时点击关闭并得到这个

error error

我该怎么办?怎么了?

最佳答案

试试这个在你的方法中 tmr_doWork_tick像这样放异步

async void tmr_doWork_Tick(对象发送者等){

//这是你的 thread.sleep();//替换为 await Task.delay(10);

关于c# - 我怎样才能延迟关机直到 virtualbox 关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37212039/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com