Код: Выделить всё
IEnumerator- Я вызываю веб-службу для создания запроса
- Я опрашиваю веб-службу, чтобы узнать, когда она готова вернуть результаты
- Как только веб-служба готова вернуть результаты, я вызываю метод (например, GetNext(n)), чтобы получить из него n элементов
- Как только GetNext(n) вернет меньше n результатов, я получил все свои элементы.
Вот упрощенная версия моего кода:
Код: Выделить всё
public class MyEnumerable : IEnumerable
{
private MyWebService _service;
private int _queryID;
public MyEnumerable(MyWebService service, int queryID)
{
_service = service;
_queryID = queryID;
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MyEnumerator(_service, _query);
}
}
public class MyEnumerator : IEnumerator
{
private List _items; //want to load my items from WebService into this
private MyWebService _service;
private int _queryID;
private int _index = 0;
private MyEnumerator(MyWebService service, int queryID)
{
_service = service;
_queryID = queryID;
}
public object Current
{
//what goes here?
}
public bool MoveNext()
{
//what goes here? would I call the web service here?
}
public void Reset()
{
_index = 0;
}
}
Подробнее здесь: https://stackoverflow.com/questions/204 ... eb-service
Мобильная версия