![](/img/trans.png)
[英]Moved some code to a new class why im getting cannot convert error on the AnimatedPictureBox[] pbs?
[英]Why im getting an error when creating an event in my new class?
我不理解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'不能用作泛型類型或方法'System.EventHandler'中的類型參數'TEventArgs'。 沒有從'GatherLinks.BackgroundWebCrawling'到'System.EventArgs'的隱式引用轉換。
EventHandler<T>
簽名(至少最初是)用於args
(在common sender
/ args
模式中)是EventArgs
某個子類的場景。 因此,有一個where T : EventArgs
約束(編輯 - 作為ByteBlast說明:直到.NET 4.5,其中約束被刪除 )
BackgroundWebCrawling
不是 EventArgs
。 除此之外,沒有必要將它作為args
發送,因為你可能已經發送它( this
)作為sender
。
如果您沒有要發送的有趣args,只需使用非泛型EventHandler
,然后發送EventArgs.Empty
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.