Windows窗体将在后台自动运行

本文关键字:运行 后台 窗体 Windows | 更新日期: 2023-09-27 18:07:47

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

Source Folder:         Destination Folder:
    Start Button

我还设置了计时器后,每2分钟程序将运行。我还移动了应用程序在启动文件夹中的快捷方式。现在我想要的是第一次我按下开始按钮后,程序形式将关闭,但会在后台运行,也每次我登录PC.exe将在后台自动运行。我想要的是,在我第一次按下开始按钮后表单永远不会出现在UI中,它总是在后台运行。请告诉我我是怎么做到的。如果你不明白我的问题,请让我知道。

Windows窗体将在后台自动运行

你真的需要在你的沟通上下功夫了。这个问题措辞很糟糕。有两个选项,要么通过进程,要么通过windows start

命令行
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选项来启动一个最小化的程序

在应用程序启动时加载之前隐藏()窗口。查看regedit start with windows c#在谷歌上的例子如何启动你的应用程序与windows,并使用定时器类显示你的应用程序每x分钟,并使用show()来显示它。

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

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