【问题标题】:windows form will run in background automaticallywindows窗体将自动在后台运行
【发布时间】:2013-04-05 03:43:53
【问题描述】:

我开发了一个这样的windows窗体

Source Folder:         Destination Folder:
    Start Button

我还设置了每 2 分钟程序运行后的计时器。而且我还在启动文件夹中移动了应用程序的快捷方式。现在我想要的是在我第一次按下开始按钮后程序表单将关闭但将在后台运行并且每次我登录 PC 时 .exe 将自动在后台运行。我的意思是我第一次按下开始按钮后我想要的表单永远不会出现在 UI 中,它总是在后台运行。请帮助我如何做到这一点。 如果您不理解我的查询,请告诉我。

【问题讨论】:

  • 不太清楚你想做什么。请显示一些代码以及到目前为止的内容。
  • 搜索 Windows 服务。
  • 如果要显示某种用户界面,则不能使用 Windows 服务。正如其他人所说,这个问题没有任何意义。您需要重新表述您的问题。还请考虑显示实际的屏幕截图,而不是质量差的 ASCII 插图。

标签: c# .net windows-applications


【解决方案1】:

您确实需要加强沟通。问题措辞非常糟糕。 有 2 个选项,通过进程或 Windows 启动中的命令行

ProcessStartInfo psi = new ProcessStartInfo(realCMD.ToString(),realARGS.ToString());
                    if (domainName != null)
                        psi.Domain = domainName;
                    psi.UserName = realUsername;
                    psi.Password = securePassword;
                    psi.CreateNoWindow = true; 
                    psi.UseShellExecute = false; 

如果我们这样做,执行时总是会显示一个窗口。

在 Windows 中从命令行启动程序的命令是“start”

启动一个单独的窗口以运行指定的程序或命令。

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    AFFINITY    The new application will have the specified processor
                affinity mask, expressed as a hexadecimal number.
    WAIT        Start application and wait for it to terminate

您可能希望使用 MIN 选项来启动最小化程序

【讨论】:

    【解决方案2】:

    Hide() 应用程序启动时加载之前的窗口。在 google 上查找 regedit start with windows c# 以获取有关如何使用 windows 启动应用程序的示例,并使用 Timer 类每隔 x 分钟显示您的应用程序并使用 Show() 显示它。

    要让它在隐藏时看起来好像根本没有窗口,请禁用任务栏图标,禁用通知托盘图标,并将在任务栏中显示设置为 false。

    也许更好的方法是在程序首次启动时在 Windows 任务计划程序中创建一个任务,显示“每 x 分钟打开一次我的应用程序。”。当你的应用打开时,做你的工作,当工作完成时,或者当用户退出时,退出应用程序,应用程序将在下一个预定时间再次打开。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多