2013-07-01 26 views
2

我不明白的erorr消息,以及如何解決它,以及爲什麼發生。 這是代碼:爲什麼在我的新課堂中創建活動時發生錯誤?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ComponentModel; 
using System.Threading; 

namespace GatherLinks 
{ 
    class BackgroundWebCrawling 
    { 
     public string f; 
     int counter = 0; 
     List<string> WebSitesToCrawl; 
     int MaxSimultaneousThreads; 
     BackgroundWorker mainBackGroundWorker; 
     BackgroundWorker secondryBackGroundWorker; 
     WebcrawlerConfiguration webcrawlerCFG; 
     List<WebCrawler> webcrawlers; 
     int maxlevels; 
     public event EventHandler<BackgroundWebCrawling> ProgressEvent; 

的錯誤是在ProgressEvent

錯誤1類型「GatherLinks.BackgroundWebCrawling」不能在通用類型或方法被用作 類型參數「TEventArgs」 'System.EventHandler'。沒有從'GatherLinks.BackgroundWebCrawling'轉換爲 'System.EventArgs'的隱式引用 。

回答

10

EventHandler<T>簽名是(至少最初)用於場景,其中args(在共同sender/args圖案)是EventArgs一些子類。這樣,有一個where T : EventArgs約束(編輯 - 如ByteBlast注意到:直到.NET 4.5,其中constraint is removed

BackgroundWebCrawling一個EventArgs。除此之外,將其作爲args發送將不會有任何意義,因爲您大概已經將其發送(this)作爲sender

如果您沒有感興趣的參數發送,只需使用非通用EventHandler,併發送EventArgs.Empty

相關問題