首页 > 解决方案 > 如何从我的控制台应用程序打开多个 http 链接?

问题描述

我创建了一个控制台应用程序,我想在特定时间触发多个链接。搜索后我做了这样的事情:

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 调度程序和这个控制台应用程序在特定时间启动控制台应用程序。

标签: c#asp.net-mvc-4cron

解决方案


你可以试试这个。使用 useProcess.Start并将 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);

推荐阅读