특정 사용자 지정 개체에 허용되는 최대 필드를 찾기 위해 매우 간단한 호출을 포함하려는 기존 RIA 서비스가 있습니다. 값이 자주 변경되는 경우가 드물기 때문에 필요한 경우 한 번만 호출 한 다음 클라이언트에 보관합니다. 그러나 가치를 알 필요가있을 때, 나는 즉시 그것을 사용할 것이므로 동기식으로 그것을 알아야합니다.동기식 RIA 요청 방법
나는이 코드 블록이 실행될 때 서비스가 실제로 요청을하지 않기 때문에 다음을 시도했지만 .Value
은 항상 단지 0입니다. 나중에 언젠가는. 는 RIA 서비스를 사용 동기,로드 온 디맨드 서비스 요청을 만들 수있는 방법
private static readonly Lazy<int> _fieldCount =
new Lazy<int>(() =>
{
const int TotalWaitMilliseconds = 2000;
const int PollIntervalMilliseconds = 500;
// Create the context for the RIA service and get the field count from the server.
var svc = new TemplateContext();
var qry = svc.GetFieldCount();
// Wait for the query to complete. Note: With RIA, it won't.
int fieldCount = qry.Value;
if (!qry.IsComplete)
{
for (int i = 0; i < TotalWaitMilliseconds/PollIntervalMilliseconds; i++)
{
System.Threading.Thread.Sleep(PollIntervalMilliseconds);
if (qry.IsComplete) break;
}
}
// Unfortunately this assignment is absolutely worthless as there is no way I've discovered to really invoke the RIA service within this method.
// It will only send the service request after the value has been returned, and thus *after* we actually need it.
fieldCount = qry.Value;
return fieldCount;
});
있습니까? 또는 다음 중 하나를 수행해야합니다. 1) 클라이언트 코드에 상수를 포함하고 변경 될 때 업데이트를 푸시합니다. 또는 2) 완전히 동기식 방식으로 호출 할 수있는 완전히 별개의 서비스를 호스팅합니까?
콜백/위임자는 어떻게됩니까? –