좋아, 내 코드에 무엇이 잘못되었는지, 그리고 무슨 일이 일어나고 있는지 잘 모르겠습니다.
class Activity
다음과 같은 방법이 있습니다
protected struct EventParams
{
public object sender;
public EventArgs e;
}
private EventParams WaitEventRaise_Body(ref EventHandler<EventArgs> handler, int timeout)
{
AutoResetEvent receiver = new AutoResetEvent(false);
EventParams result = new EventParams();
EventHandler<EventArgs> handle = new EventHandler<EventArgs>((sender, e) =>
{
result.e = e;
result.sender = sender;
receiver.Set();
});
handler += handle;
if (timeout > 0)
{
receiver.WaitOne(timeout);
}
else
{
receiver.WaitOne();
}
return result;
}
protected EventParams WaitEventRaise(ref EventHandler<EventArgs> handler)
{
return WaitEventRaise_Body(ref handler, -1);
}
protected EventParams WaitEventRaise(ref EventHandler<EventArgs> handler, int timeout)
{
return WaitEventRaise_Body(ref handler, timeout);
}
좋습니다. 그래서 저는 AutoResetEvent를 반복해서 쓰고 있다는 것을 알게되었습니다. 그래서 저는 메서드를 만들기로 결정했습니다. 하지만 파생 클래스에서이 메서드를 호출하려고하면Bot : Activity
EventParams eventResult = WaitEventRaise(ref currentJob.JobReported);
준다
오류 30 Project.Activity.WaitEventRaise (ref System.EventHandler)에 대한 최상의 오버로드 메서드 일치에 잘못된 인수가 있습니다.
currentJob은 Job : Activity
이벤트 가있는 클래스입니다.
public event EventHandler<JobReport> JobReported;
과
class JobReport : EventArgs
제가하고 싶은 것은 일을하는 봇이 있다는 것입니다. 실제로 그것은 일자리를 만들고 그들이 일을 마칠 때까지 기다립니다. Job 클래스는 내부에서 이벤트를 발생시켜 봇 클래스가 작업을 완료했음을 알립니다. 그리고 봇 클래스는 작업이 이벤트를 발생시킬 때까지 기다립니다. 그래서 나는 그것이 명확하기를 바랍니다. 그리고 영어가 제 모국어가 아니라는 점에 대해 유감입니다.
기본적으로 그런 이벤트를 언급 할 수 없습니다. 두 가지 옵션 :
"처리기 추가"및 "처리기 제거"에 대한 대리자를 전달합니다.
EventParams eventResult =
WaitEventRaise<JobReport>(handler => currentJob.JobReported += handler,
handler => currentJob.JobReported -= handler);
다음 WaitEventRaise
과 같이 선언됩니다.
EventParams WaitEventRaise<T>(Action<EventHandler<T>> add,
Action<EventHandler<T>> remove)
where T : EventArgs
으로 이동 EventInfo
하면 반사와 인출하려는 이벤트에 해당하는
이것들 중 어느 것도별로 즐겁지 않습니다. Rx도 문제가됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다