【发布时间】:2016-07-22 12:43:44
【问题描述】:
你好,我的学校有我需要访问的记录,但我忘记了我的用户 ID,所以我制作了一个程序,可以下载任何可能的 PDF 并在其中搜索我的名字。如果它找到我的,它会在程序关闭并说“我们发现一个包含 Sean 文件名的文件是:xxxxxx.pdf”时提醒我是在一个单独的方法!顺便说一句,学校名称将被加星标!
*顺便说一句!在 Search() 中,我使用 i-10 作为临时修复,但我认为它们一定是更好的方法 *
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using BitMiracle.Docotic.Pdf; // pdf parser / viewer
using System.IO;
using System.Threading;
namespace XXXXXXX_TEMP
{
class Program
{
static void Main(string[] args)
{
Program p1 = new Program();
p1.Start();
}
private void Start()
{
WebClient wc = new WebClient();
for (int i = 200000; i < 999999999; i = i + 10)
{
try
{
wc.DownloadFile("XXXXXXXXXXXXXXXXXXXXXX/" + i + ".pdf", i + ".pdf");
}
catch (WebException) {
continue;
}
PdfDocument pdf = new PdfDocument(i + ".pdf");
Thread a = new Thread(() => Search(i, pdf));
a.Start();
if (i == 999999) {
Console.ReadLine();
}
}
}
private void Search(int i, PdfDocument pdf)
{
i = i - 10;
String html = pdf.GetText();
if (html.ToLower().Contains("sean"))
{
Console.WriteLine("Found File Containing Sean! File Name Is : " + i + ".pdf\n");
Console.WriteLine("PDF Text = " + html);
}
}
}
}
【问题讨论】:
-
这个非常常见的错误已经在许多其他 Stack Overflow Q&A 中得到解决,包括标记的重复。请特别参阅this answer 以获得很好的解释。
-
@PeterDuniho 非常抱歉,这经常发生在我身上,因为我在措辞上有问题。对不起,下次我会更加小心。
标签: c# multithreading pdf webclient