开发者

Run task in Visual Basic?

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


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);
            }
        }
    }
}


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜