所以我有一個用C#編寫的基本應用程序。它基本上寫了一個庫存文件。它會在創建文件時停下來。我對這裏發生的事情感到困惑,因爲如果我在IDE中運行它,它將停止工作。該文件在文件的不同停止處停止,因此它不是一個單獨的事件。如果使用不同的話,我正在使用線程池。我有一個循環遍歷文件並讀取文件並提示新線程。如果沒有錯誤,就很難調試某些東西。編程崩潰原因未知
static void Main(string[] args)
{
//string asins;
Readfile r = new Readfile();
r.read();
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
//Thread.Sleep(60000);
//createoutward c = new createoutward();
// c.read();
//p.print(s.scrap(r.read()));
}
我的方法使得線程
public string[] read()
{
ThreadPool.SetMaxThreads(10, 100);
string[] asins;
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Joe T\Desktop\AmazonAsins.csv");
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"\\WIN-UWPWZ7Z3RKX\wwwroot\repricer\WriteLines2a.txt"))
file.WriteLine("Product-ID\tPrice1\tPrice2\tRank\tAFN\t" + DateTime.Now);
prices = new string[lines.Length, 2];
int i = 0;
asins = new string[lines.Length];
foreach (string line in lines)
{
scraping s = new scraping();
char[] tabs = { '\t' };
string asin;
string[] words = line.Split(tabs);
asin = words[1];
asins[i] = asin;
Thread.Sleep(1000);
ThreadPool.QueueUserWorkItem(new WaitCallback(s.scraping1), asin);
++i;
}
return asins;
}
刮痧類
public void scraping1(object a)
{
string AFN = "N";
string asin = (string)a;
double price, price2;
string sprice;
string context;
string page = "*****" + asin;
try
{
WebZinc WebZincProduct = new WebZinc();
WebZincProduct.OpenPage(page);
context = WebZincProduct.CurrentPage.Text;
}
catch
{
scraping1(a);
return;
}
Regex regex11 = new Regex("****\r\n((.|\n)*?)****",
RegexOptions.IgnoreCase);
Match oP1 = regex11.Match(context);
if (oP1.Value.Contains("*******"))
{
AFN = "Y";
}
Regex reg = new Regex(@"[0-9]+\.[0-9]+");
MatchCollection mc = reg.Matches(oP1.Value);
double cost = 0.0;
double cost2 = 0.0;
double shipping2 = 0.0;
double shipping = 0.0;
int j = 0;
int j3 = 0;
foreach (Match m in mc)
{
if (j == 0) cost = Convert.ToDouble(m.Value);
if (j == 1) shipping = Convert.ToDouble(m.Value);
Console.WriteLine("{0}", m.Value);
++j;
}
Regex regex4 = new Regex("****\r\n\r\n((.|\n)*?)****",
RegexOptions.IgnoreCase);
Match oP4 = regex4.Match(context);
MatchCollection mc4 = reg.Matches(oP4.Value);
foreach (Match m in mc4)
{
if (j3 == 0) cost2 = Convert.ToDouble(m.Value);
if (j3 == 1) shipping2 = Convert.ToDouble(m.Value);
Console.WriteLine("{0}", m.Value);
++j3;
}
price2 = cost2 + shipping2;
price = cost + shipping;
if (price == 0.0 && i != 5)
{
scraping1(a);
}
string rank = rankAFN(asin);
lock (Program._locker)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"\\WIN-UWPWZ7Z3RKX\wwwroot\repricer\WriteLines2a.txt", true))
file.WriteLine(asin + "\t" + price + "\t" + price2 + "\t" + rank + "\t" + AFN);
}
}
當我們看不到您的代碼時,也很難知道發生了什麼;) – slandau
@slandau添加了代碼 –
當您說你在IDE中運行它時,是否使用「開始調試」[F5]或「開始不調試「[Ctrl] + [F5] –