我正在使用 aParallel.ForEach
来调用并创建一个新类。
Parallel.ForEach(urlTable.AsEnumerable(),drow =>
{
using (var WCC = new MasterCrawlerClass() )
{
WCC.MasterCrawlBegin(drow);
}
});
MasterCrawlerClass
包含private static voids
和private static string
。我想我的问题是这个。既然我在 myforeach
中调用一个新类,那么我voids
/strings
在那个新类实例中的所有 / 都是安全的吗?
class MasterCrawlerClass : IDisposable
{
public void Dispose()
{
GC.Collect();
}
public static void SetNewProxy()
{
string mysql_Proxyserver_ProxyPort = "select ProxyServer,ProxyPort,ResponseTime FROM proxies.tblproxies where Active = 1 and DateTested >= Date_sub(CurDate(),INTERVAL 2 day) and ResponseTime <= 3 order by Rand() limit 1";
DataTable proxyDT = new DataTable();
proxyDT = DTTable(mysql_Proxyserver_ProxyPort, "mysql_Proxyserver_ProxyPort");
ProxyServer = proxyDT.Rows[0].ItemArray[0].ToString();
ProxyPort = Convert.ToInt32(proxyDT.Rows[0].ItemArray[1].ToString());
}
private static string HTMLModelProcess(string inputString)
{
string returnString = string.Empty;
string ModelString = inputString.Replace("Certified", "").Replace("Used", "").Trim();
string[] makeModelSplit = ModelString.Split(new char[] { ' ' }, 4);
returnString = makeModelSplit[2];
return returnString;
}
private static string ProxyServer { get; set; }
private static int ProxyPort { get; set; }
}
private static DataTable DTTable(string mysqlQuery, string queryName)
{
DataTable DTTableTable = new DataTable();
try
{
MySqlDataAdapter DataDTTables = new MySqlDataAdapter(mysqlQuery, MySQLProcessing.MySQLStatic.Connection);
DataTable DataDTTablesDT = new DataTable();
DataDTTables.SelectCommand.CommandTimeout = 240000;
DataDTTables.Fill(DataDTTablesDT);
DTTableTable = DataDTTablesDT;
}
catch (Exception ex)
{
GenericLogging("Failed MySQLquery: " + ex.Message.ToString(), "MySQLProcessor", "DTTable", "", "MysqlError", "", queryName, mysqlQuery);
}
return DTTableTable;
}
MysqlProcessing.Mysqlstatic.Connection 是在 Parallel 之前设置的,永远不要改变。
这是更多voids
一些strings
。我还不完全理解线程,所以我正在努力解决它。