簡體   English   中英

為什么我在新課程中創建活動時出錯?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM