English 中文(简体)
零式 desktop——系统通风。 避免一切时间工作
原标题:Formless desktop app - SystemEvents.SessionEnding not working all the time
  • 时间:2011-01-03 05:39:38
  •  标签:
  • c#

我有一份显示大多数时间形式的数字,我需要当用户关闭该系统时,自己结束。

因此,我设立了a 问题,以及该系统的答复。 开会似乎奏效。

首先。

我的<代码>Program.Main()方法:

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    #region Pre-launch stuff
    // Are we upgrading from an older version? We need to grab our old settings!
    if (Properties.Settings.Default.UpgradeSettings)
    {
        Properties.Settings.Default.Upgrade();
        Properties.Settings.Default.UpgradeSettings = false;
        Properties.Settings.Default.Save();
    }

    // Visual styles
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    #if !DEBUG
    // Add the event handler for handling UI thread exceptions to the event.
    Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandling.Application_ThreadException);

    // Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

    // Add the event handler for handling non-UI thread exceptions to the event. 
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ErrorHandling.CurrentDomain_UnhandledException);
    #endif

    // Since we have no forms open we need to watch for the shutdown event; otherwise we re blocking it
    SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);

    // ...
    // ...
    // ...

    Application.Run();
}

方法SystemEvents_SessionEnding a. 采用<代码>Exit(<>Exit()”的方法。

    public static void Exit()
    {
        MessageBox.Show("test");

        try
        {
            IconHandler.SuperNotifyIcon.Dispose();
        }
        finally
        {
            Application.Exit();
        }
    }

然而,我的 app子有时关闭。 我补充说的信息箱没有显示。

我可以指出,这种简单、简单的执行道路可能失败。 但是,它确实如此,这对我和我的用户来说都是一个很大的刺激。

任何想法? Though倒?


http://www.un.org。

Per corvuscorax s response, I ve试图增加一个表格,但行动迟缓——首先,我有这样的文字:

        ShowInTaskbar = false;
        WindowState = FormWindowState.Minimized;
        Shown += (sender, e) => Hide();

并修改了<代码>Program.Exit()方法,以关闭该表,该表将同时在<代码>上操作处置代码。 表格Closing activity。

该表格从接收的电文中删除。 我现在评论了这条线,但即便如此,我还是发现,封锁正在发生。 一旦我点击了1顿I,以显示表格并试图再次关闭,就顺利完成。

最佳回答

我建议不要有任何形式。

诚然,WinForms应用正常,把主要形式隐藏起来,而且你总是能够处理所有信息。

Addendum

作为这样做的一种额外红利,在发展过程中,你也获得了自由的独角,通过不隐藏主要形式,你可以有轻松的产出观点、模拟投入、与纽托邦采取行动、各种有益的障碍。

Addendum 2

这里,我通常如何产生看不见的主要形式。 在建筑商中,添加:

if (!Debugger.IsAttached)
{
    // Prevent the window from showing up in the task bar AND when Alt-tabbing
    ShowInTaskbar = false;
    FormBorderStyle = FormBorderStyle.FixedToolWindow; 

    // Move it off-screen
    StartPosition = FormStartPosition.Manual;
    Location = new Point(SystemInformation.VirtualScreen.Right+10, SystemInformation.VirtualScreen.Bottom+10);
    Size = new System.Drawing.Size(1, 1);
}

如果不从夸大公司内部运作,这将掩盖窗户。

问题回答

贵国的法典是否有信息泵?

您在申请的每个用户接口内需要一个信息泵,以便发送和处理任何针对您申请的窗口信息。 即便您从未在屏幕上展示过一个表格,如果阅读器是用户界面,届时仍会发出其他系统信息,需要发送和处理。

在典型的WinForms应用中,电传泵站在电话中......

Application.Run(new MyForm());

......在我的审理结束之后,它才撤出。 在你看来,你从未向申请方发出过呼吁。 操作方法或类似方法。 在这种情况下,你不处理窗户信息。 因此,当你不展示表格时,你处理 lo什么?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签