我已经编写了一个库,可以使用我们的自定义嵌入式硬件处理所有TCP / IP通信。它与我们的大多数内部软件一起使用,将来可能会单独出售。
最令人烦恼的是,每次我处理来自库的事件时,我都必须有一个单独的函数来调用。我只能想象有一种更简单的方法可以做到这一点我不知道...
有什么想法吗?
public Setup(DiscoveryReader reader)
{
download = new DownloadFilesIndividual(Reader.ip, DateTime.Today);
download.OnDownloadStatus += new DownloadStatusHandler(download_OnDownloadStatus);
}
void download_OnDownloadStatus(DownloadStatus status)
{
Invoke(new DownloadStatusHandler(this.safe_download_OnDownloadStatus), new object[] { status });
}
void safe_download_OnDownloadStatus(DownloadStatus status)
{
// Do UI stuff here
}
答案 0 :(得分:1)
语法糖
public Setup(DiscoveryReader reader)
{
download = new DownloadFilesIndividual(Reader.ip, DateTime.Today);
download.OnDownloadStatus += new DownloadStatusHandler(download_OnDownloadStatus);
}
void download_OnDownloadStatus(DownloadStatus status)
{
if(InvokeRequired)
{
Invoke(new Action<DownloadStatus>(download_OnDownloadStatus),status);
} else {
// Do UI stuff here
}
}