我正在处理来自其父窗体的子窗体中的事件,并且当我尝试从处理程序的事件args中包含的列表中添加项目时(在下面的代码中为ScraperForm_SiteScraped),我在控制台中收到异常System.InvalidOperationException 。有趣的是,它似乎在第一次添加时就成功了,但是没有后续尝试。public partial class ProxyTesterView : UserControl{ private BindingList<Proxy> proxies = new BindingList<Proxy>(); private BindingList<ProxyJudge> pudges = new BindingList<ProxyJudge>(); private BindingList<ProxyTest> tests = new BindingList<ProxyTest>(); private PauseOrCancelTokenSource pcts = new PauseOrCancelTokenSource(); private ProxyScraperForm scraperForm = new ProxyScraperForm(); public ProxyTesterView() { InitializeComponent(); proxies.ListChanged += Proxies_ListChanged; scraperForm.SiteScraped += ScraperForm_SiteScraped; } private void Proxies_ListChanged(object sender, ListChangedEventArgs e) { ProxiesDataGridView.RowCount = proxies.Count; } private void AddFromScraperToolStripMenuItem_Click(object sender, EventArgs e) { scraperForm.Show(); } private void ScraperForm_SiteScraped(object sender, SiteScrapedEventArgs e) { foreach (var proxy in e.ScrapedProxies) { proxies.Add(proxy); } }}子表格public partial class ProxyScraperForm : Form{ private BindingList<IProxyScraperSite> sites = new BindingList<IProxyScraperSite>(); public int ScrapeInterval { get; set; } = 60000; public event EventHandler<SiteScrapedEventArgs> SiteScraped; public ProxyScraperForm() { InitializeComponent(); sites.Add(new ProxyScraperSiteUsProxyOrg()); sites.Add(new ProxyScraperSiteFreeProxyListNet()); sites.Add(new ProxyScraperSiteFreeProxyListsNet()); sites.Add(new ProxyScraperSiteHideMyName()); sites.Add(new ProxyScraperSiteHidester()); ScraperDataGridView.DataSource = sites; }
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
- 1 回答
- 0 关注
- 180 浏览
添加回答
举报
0/150
提交
取消