我有一个现有的RIA服务,我想在其中包含一个非常简单的调用来查找某个自定义对象允许的最大字段。这个值很少会改变,如果有的话,我想在需要时只调用一次,然后保存在客户端。但是,当我需要知道价值时,我需要以同步的方式了解它,因为我将立即使用它。如何进行同步RIA请求
我试过以下方法,但.Value
始终只是0,因为当这段代码运行时服务实际上没有发出请求,而是稍后一段时间。
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;
});
有任何方式,使使用RIA服务同步,负载点播服务呼叫?或者我必须要么:1)在客户端代码中包含常量,并在/如果它发生更改时推出更新;或2)主持一个完全独立的服务,我可以以同步方式调用?
回调/代表呢? –