C# 如何从我的控制台应用程序打开多个http链接?

C# 如何从我的控制台应用程序打开多个http链接?,c#,asp.net-mvc-4,cron,C#,Asp.net Mvc 4,Cron,我创建了一个控制台应用程序,希望在其中的特定时间触发多个链接。搜索后,我执行了以下操作: using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Net.Mail; using System.Text; using System.Threading.Tasks; name

我创建了一个控制台应用程序,希望在其中的特定时间触发多个链接。搜索后,我执行了以下操作:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace cronjob_Test_App
{
    class Program
    {
         static void Main(string[] args)
        {
            StartProcess();
        }
        public static void StartProcess()
        {
            // Process.Start("https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe");

            var psi = new ProcessStartInfo("chrome.exe");
            string a, b;
            a = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
            b = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
            psi.Arguments = a;
            Process.Start(psi);
            psi.Arguments = b;
            Process.Start(psi);
 }

    }
}
它同时启动所有链接。我希望第一个链接完成,然后启动第二个链接。我怎么做,或者如果有其他好方法,请建议。
我正在使用windows scheduler和此控制台应用程序在特定时间启动控制台应用程序。

您可以尝试此操作。使用
过程。启动
并将url设置为第二个参数

string a = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
string b = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
Process.Start("chrome.exe", a);
Process.Start("chrome.exe", b);

你可以试试这个。使用
过程。启动
并将url设置为第二个参数

string a = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
string b = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
Process.Start("chrome.exe", a);
Process.Start("chrome.exe", b);

使用进程。WaitForExit()

您还可以向方法添加一个以(int)毫秒为参数的时间延迟

string a = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
string b = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
Process.Start("chrome.exe", a);
Process.Start("chrome.exe", b);
示例:
p1.WaitForExit(500)

PS:该过程不会等待整个网页加载

已编辑

如果您试图下载文件,请使用


使用进程。WaitForExit()

您还可以向方法添加一个以(int)毫秒为参数的时间延迟

string a = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
string b = "https://notepad-plus-plus.org/repository/7.x/7.5.7/npp.7.5.7.Installer.exe";
Process.Start("chrome.exe", a);
Process.Start("chrome.exe", b);
示例:
p1.WaitForExit(500)

PS:该过程不会等待整个网页加载

已编辑

如果您试图下载文件,请使用



你为什么要这么做?你介意使用
WebClint
类吗?如果有一种使用web客户端的方法,请在其中进行指导。我也可以使用web客户端。我写了一个答案,你可以试试。你不能这样做。你没有真正的方法来安排这些下载(当然,你可以,但它会变得非常复杂,毫无意义)。正如已经提出的,使用,它是建立更多的ol少为这一点。请看下面的示例。还有(许多人中的一个):。谢谢让我试试这个。你为什么要这么做?你介意使用
WebClint
类吗?如果有一种使用web客户端的方法,请在其中进行指导。我也可以使用web客户端。我写了一个答案,你可以试试。你不能这样做。你没有真正的方法来安排这些下载(当然,你可以,但它会变得非常复杂,毫无意义)。正如已经提出的,使用,它是建立更多的ol少为这一点。请看下面的示例。还有(众多链接中的一个):.谢谢,让我试试。你的回答是肯定的,但WaitforExit()工作不正常。它只需等待几秒钟,第二个链接就开始工作。有没有办法,第二个链接在第一个链接完成之前不会启动?@SadiaRashid这正是我在回答中提到的,它不会等到整个页面被加载/文件被下载,这与chrome.exe处理的事情完全不同itself@SadiaRashid我已经更新了答案,编辑可能会对您有所帮助。@SadiaRashid很乐意提供帮助,如果这解决了您的问题,请将其标记为已接受的答案!:)您的回答是肯定的,但WaitforExit()没有正常工作,它只是等待几秒钟,然后第二个链接开始工作。有没有可能第二个链接在第一个链接完成之前不会启动?@SadiaRashid这正是我在回答中提到的,它不会等到整个页面被加载/文件被下载,这与chrome.exe处理的事情完全不同itself@SadiaRashid我已经更新了答案,编辑可能会对您有所帮助。@SadiaRashid很乐意提供帮助,如果这解决了您的问题,请将其标记为已接受的答案!:)