Form1 からクラスに変数を渡すために、後で Form1 でインスタンスを作成するこのクラスがあります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GatherLinks
{
class WebcrawlerConfiguration
{
public string url;
public int levels;
public string mainurl;
public Dictionary<string,List<string>> localy;
public bool removeext;
public bool downloadcontent;
public int failedUrls;
public bool toCancel;
public System.Threading.ManualResetEvent busy;
public WebcrawlerConfiguration()
{
}
}
}
このクラスが Form1 から変数を取得するようにするにはどうすればよいですか? クラスのインスタンスを作成するときに、クラスの各変数は Form1 の変数を取得する必要があります。
それから私はこのクラスを持っています:
class BackgroundWebCrawling
{
int counter = 0;
List<string> WebSitesToCrawl;
BackgroundWorker mainBackGroundWorker;
BackgroundWorker secondryBackGroundWorker;
WebCrawler webcrawler1;
WebcrawlerConfiguration webcrawlerCFG;
public BackgroundWebCrawling()
{
mainBackGroundWorker = new BackgroundWorker();
mainBackGroundWorker.DoWork += mainBackGroundWorker_DoWork;
}
private void mainBackGroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < WebSitesToCrawl.Count; i++)
{
if (counter >= 3)
{
Thread.Sleep(10);
}
else
{
webcrawler1 = new WebCrawler(webcrawlerCFG);
counter++;
secondryBackGroundWorker = new BackgroundWorker();
secondryBackGroundWorker.DoWork += secondryBackGroundWorker_DoWork;
}
}
}
private void secondryBackGroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (offlineOnline == true)
{
offlinecrawling(f, levelsToCrawl, e);
}
else
{
webcrawler1.webCrawler(
}
counter--;
}
ここの下部では、次のことを行っています: webcrawler1.webCrawler( 関数 webCralwer は、最初のクラス WebcrawlerConfiguration からすべての変数を取得する必要があります。
WebCrawler 関数は次のようになります。
public List<string> offlinecrawling(string url, int levels, string mainurl, Dictionary<string, List<string>> localy, bool removeext, bool downloadcontent, int failedUrls, bool toCancel, System.Threading.ManualResetEvent busy)
だから今私がやっているとき webcrawler1.webCrawler( それはすべての変数を求めています...しかし、私は WebcrawlerConfiguration.
どうすればできますか?