【问题标题】:C# - Background application with GUIC# - 带有 GUI 的后台应用程序
【发布时间】:2015-12-30 18:29:25
【问题描述】:

我的问题是我想创建一个后台应用程序,但它的用户界面可以恢复并最小化到系统托盘,并且它从 windows 开始。我尝试搜索如何开始,但我只找到了关于没有 UI 或创建表单并隐藏它的 Windows 服务的线程。所以我的问题是我应该如何开始?一个 Windows 窗体?一个服务并以某种方式添加一个接口?

谢谢!

【问题讨论】:

  • 作为服务运行的应用程序不能有可见的 UI。 (从技术上讲它可以 - 但 Windows 将始终将其隐藏。)

标签: c# user-interface background-application


【解决方案1】:

如果您希望您的应用程序在用户登录时启动,那么创建并隐藏它是一种方法。

如果您希望代码在没有用户登录的情况下也能运行,那么您将需要 Windows 服务。

如果您选择走这条路,您很可能希望有一个应用程序以某种方式与您的服务交互。

【讨论】:

    【解决方案2】:

    这是一种创建与表单无关的应用程序的方法。使用标准 WinForms 项目,但将 ApplicationContext 的自定义实现传递给 Application.Run()

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyContext());
        }
    
    }
    
    public class MyContext : ApplicationContext
    {
    
        public MyContext()
        {
            // this is the new "entry point" for your application
    
            // use Application.Exit() to shut down the application
    
            // you can still create and display a NotifyIcon control via code for display in the tray
            // (the icon for the NotifyIcon can be an embedded resource)
            // you can also display forms as usual when necessary
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 2010-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多