에 비동기 이벤트를 제한하여 프로그램의 다른 부분에서 사용되는 일부 계산을 수행하는 클래스를 만들었습니다. 이 클래스는 데이터베이스의 데이터를 필요로하므로 WCF-Service를 호출하여 데이터를 가져옵니다. 클래스의 구조는 다음과 같습니다 계산-클래스를 참조하고 CalculationFinished 이벤트에 가입 할 필요가내 C# -Silverlight-3-Application의 호출 객체
public class ConsumptionCalculation
{
// Declare the event to notify subscribers, that the calculation has finished
public delegate void HandlerConsumtionCalculationFinished(object sender, ConsumtionCalculationArgs args);
public event HandlerConsumtionCalculationFinished CalculationFinished;
public void Do(int id)
{
// call the WCF-Service
DataContainer.instance.dataSource.GetConsumtionInfoAsync(id);
}
void dataSource_GetConsumtionInfoCompleted(object sender, GetConsumtionInfoCompletedEventArgs e)
{
// Receive the result of the WCF-Service call
// do some calculation here and put the results in the variable 'args'
// Raise an event to notify listeners, that the calculation is finished
CalculationFinished(this, args);
}
}
개체를.
public class IUseTheCalculation
{
ConsumptionCalculation _calcObject;
public IUseTheCalculation()
{
_calcObject = new ConsumptionCalculation();
_calcObject.CalculationFinished += new HandlerConsumptionCalculationFinished(CalculationFinishedEvent);
}
private void CalculationFinishedEvent(object sender, ConsumptionCalculationArgs args)
{
// use the calculation to display data or write it to a file or whatever
}
}
은 두 개 이상의 클래스 각각 자신의 ConsumptionCalculation-개체가있는 IUseTheCalculation 클래스처럼있다.
내 문제는 다음과 같다 : 나는 클래스 중 하나의 ConsumptionCalculation 객체의 마 - 메서드를 호출 할 때 , 어떤 ConsumptionCalculation 객체에 대한 참조가 모든 클래스는, 결과 CalculationFinished 이벤트를 받게됩니다. 모든 기존 ConsuptionCalculation- 개체가 WCF 서비스에서 dataSource_GetConsumtionInfoCompleted 이벤트를 받기 때문에 이것이라고 생각합니다. 그러나 이벤트를 수신하는 호출 객체 만 원합니다. 이런 종류의 문제에 대한 표준 접근법이 있다고 생각하지만 아직 이해할 수는 없습니다. 이 문제를 어떻게 해결하겠습니까? 사전에
감사합니다, 프랭크
비동기 프록시를 직접 구현하지 않고 생성 한 이유가 무엇입니까? –
죄송 합니다만, 귀하의 요점을 모르겠습니다. – Aaginor