0

我有一个记录一些用户数据的应用程序。如果用户注销工作站,则需要保存此信息。

该程序是一个 windows 窗体 c# 应用程序。

目前我正试图通过下面的这个函数来做到这一点,它可以工作到 95%,但不能达到 100%。

    Application.Run(new Shutdown(_object));

    private void Shutdown_FormClosing(object sender, FormClosingEventArgs e)
    {
        e.Cancel = true;``
        _object.LogLogout(); //Save the logout to a file

    }

我也尝试了该功能,但这根本不起作用。我不明白为什么。有什么提示吗?我完全被困在这里。

    Microsoft.Win32.SystemEvents.SessionEnded += new Microsoft.Win32.SessionEndedEventHandler(SystemEvents_SessionEnded);
    Microsoft.Win32.SystemEvents.SessionEnding += new Microsoft.Win32.SessionEnding(SystemEvents_SessionEnding);
4

1 回答 1

1

找到答案,只有在表单仍然可见时才会停止关闭。事实并非如此。因此我通过这样做解决了这个问题。

    private void Shutdown_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (systemShutdown)
        {
            this.Show();
            //If GUI got closed delted active entry and log off
            _object.LogLogout(); //Save the logout to a file
            Thread.Sleep(100);
            this.Hide();
        }
    }
于 2018-02-20T19:49:22.543 回答