为什么我在新课程中创建活动时出错?

时间:2013-07-01 06:46:09

标签: c# events generics

我不理解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'。

1 个答案:

答案 0 :(得分:10)

EventHandler<T>签名(至少最初是)用于args(在公共sender / args模式中)是{{的某些子类的方案。 1}}。因此,存在EventArgs约束(编辑 - 如ByteBlast注释:直到.NET 4.5,其中constraint is removed

where T : EventArgs BackgroundWebCrawling。除此之外,没有必要将其作为EventArgs发送,因为您可能已将其发送(args)为this

如果您没有要发送的有趣参数,只需使用非通用sender,然后发送EventHandler

相关问题