在 Visual Basic 中运行任务?

发布于 2024-11-18 19:00:52 字数 102 浏览 1 评论 0原文

我正在用 VB 编写一个小应用程序,我想知道如何设置它,以便当用户按下按钮时,运行预定任务。请记住,该任务已经创建,我只需要运行它即可。

有什么想法吗?

谢谢

I am writing a small app in VB and I would like to know how I would set it up so that when a user pressed a button, a sechduled task is ran. Keep in mind that this task is already created, I just need it to run.

Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中二柚 2024-11-25 19:00:52

使用 System.Diagnostics.Process 类。您可以创建一个进程并使用 Process.Start() 方法运行它。

编辑:
以下代码示例启动 helloworld.exe。这只是为了提供有关 Process 类的想法。您可以在 Process.Start Method 中找到此示例

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                // This code assumes the process you are starting will terminate itself. 
                // Given that is is started without a window so you cannot terminate it 
                // on the desktop, it must terminate itself or you can do it programmatically
                // from this application using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Use the System.Diagnostics.Process class. You can create a process and run it with Process.Start() method.

EDIT:
Following code sample starts the helloworld.exe. This is just to give an idea about the Process class. You can find this example in Process.Start Method

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                // This code assumes the process you are starting will terminate itself. 
                // Given that is is started without a window so you cannot terminate it 
                // on the desktop, it must terminate itself or you can do it programmatically
                // from this application using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
↙厌世 2024-11-25 19:00:52

使用最近添加的 System.Threading.Tasks 库怎么样?

链接: http://msdn.microsoft.com/en-us /library/system.threading.tasks.aspx

How about using the recently added System.Threading.Tasks library?

Link: http://msdn.microsoft.com/en-us/library/system.threading.tasks.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文