我想從SendNotification方法中的this.Job.JobCompleted中調用Job_JobCompleted事件。但是,這個.job顯示我爲空,所以我無法稱呼它。請以任何方式幫助我或以任何方式致電Job_JobCompleted事件。謝謝從方法c調用事件#
public override void SendNotification(string content)
{
this.Job.JobCompleted += Job_JobCompleted;
}
void Job_JobCompleted(object sender, JobCompletionData e)
{
//List<string> crawledUrls = new List<string>(); // List of included URLS in c#
//crawledUrls.Add("http://www.friferie.dk/inspiration/India");
//crawledUrls.Add("http://www.friferie.dk/inspiration/UK");
//crawledUrls.Add("http://www.friferie.dk/inspiration/Spain");
//crawledUrls.Add("http://www.friferie.dk/inspiration/Nigeria");
//crawledUrls.Add("http://www.friferie.dk/inspiration/Uganda");
string comment = @"sitemap-generator-url=http://www.auditmypc.com/free-sitemap-generator.asp" + Environment.NewLine + Environment.NewLine +
"This sitemap was created using the free tool found here: http://www.auditmypc.com/free-sitemap-generator.asp" + Environment.NewLine + Environment.NewLine +
"Audit My PC also offers free security tools to help keep you safe during internet travels";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XElement root = new XElement("urlset",
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"),
new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
new XComment(comment));
List<XElement> ChildNodes = new List<XElement>();
foreach (string url in e.CrawledUrls)
{
ChildNodes.Add(CreateXMLNode(url));
}
root.Add(ChildNodes);
root.Save("d:/product.xml");
}
public static XElement CreateXMLNode(string url)
{
XElement urlnode = new XElement("url");
urlnode.Add(new XElement("loc", url));
return urlnode;
}
只能在聲明事件的類內調用事件。請參閱[事件教程](https://msdn.microsoft.com/en-us/library/aa645739(v = vs.71).aspx)。你正在嘗試提升'Job'屬性中的某個對象的'JobCompleted'事件。你不能這樣做。只有'Job'對象可以引發這個事件。什麼應該引發這個事件? –