当前位置: 首页>>代码示例>>C#>>正文


C# ObservableCollection.IsNullOrEmpty方法代码示例

本文整理汇总了C#中System.Collections.ObservableCollection.IsNullOrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.IsNullOrEmpty方法的具体用法?C# ObservableCollection.IsNullOrEmpty怎么用?C# ObservableCollection.IsNullOrEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.ObservableCollection的用法示例。


在下文中一共展示了ObservableCollection.IsNullOrEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadFavoritesAudios

        private async void LoadFavoritesAudios(CancellationToken token)
        {
            IsWorking = true;
            OnTaskStarted("favorites");

            FavoritesTracks = new ObservableCollection<Audio>();

            try
            {
                int offset = 0;
                int count = 50;
                int requestsCount = 0;

                while (FavoritesTracks != null && FavoritesTracks.Count < MAX_WALL_AUDIOS)
                {
                    var a = await DataService.GetFavoritesAudio(count, offset, 0, token);
                    if (a == null || a.Count == 0)
                        break;
                    else if (a.Count > 0)
                    {
                        OnTaskFinished("favorites");
                    }

                    if (token.IsCancellationRequested)
                    {
                        Debug.WriteLine("Favorites audios cancelled");
                        break;
                    }

                    offset += count;

                    foreach (var audio in a)
                    {
                        FavoritesTracks.Add(audio);
                    }

                    requestsCount++;

                    if (requestsCount >= 2) //не больше 2-х запросов в секунду
                    {
                        requestsCount = 0;
                        await Task.Delay(1000);
                    }

                    Debug.WriteLine("Loading more audios from favorites");
                }

                if (FavoritesTracks.IsNullOrEmpty() && !token.IsCancellationRequested)
                    OnTaskError("favorites", ErrorResources.LoadAudiosErrorEmpty);
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);

                OnTaskError("favorites", ErrorResources.LoadAudiosErrorCommon);
            }

            IsWorking = false;
            OnTaskFinished("favorites");
        }
开发者ID:kostyatab,项目名称:meridian,代码行数:60,代码来源:MusicViewModel.cs

示例2: LoadNewsAudios

        private async void LoadNewsAudios(CancellationToken token)
        {
            IsWorking = true;
            OnTaskStarted("news");

            NewsTracks = new ObservableCollection<Audio>();

            try
            {
                var nextFrom = string.Empty;
                int count = 150;
                int requestsCount = 0;

                while (NewsTracks != null && NewsTracks.Count < MAX_NEWS_AUDIOS)
                {
                    if (token.IsCancellationRequested)
                    {
                        Debug.WriteLine("News audio cancelled");
                        break;
                    }

                    var a = await DataService.GetNewsAudio(count, nextFrom, token);
                    if (a.Items.IsNullOrEmpty())
                        break;
                    else if (a.Items.Count > 0)
                    {
                        OnTaskFinished("news");
                    }

                    if (token.IsCancellationRequested)
                    {
                        Debug.WriteLine("News audio cancelled");
                        break;
                    }

                    nextFrom = a.NextFrom;

                    foreach (var audio in a.Items)
                    {
                        NewsTracks.Add(audio);
                    }

                    requestsCount++;

                    if (requestsCount >= 2) //не больше 2-х запросов в секунду
                    {
                        requestsCount = 0;
                        await Task.Delay(1000);
                    }

                    Debug.WriteLine("Loading more audios from news");
                }

                if (NewsTracks.IsNullOrEmpty() && !token.IsCancellationRequested)
                    OnTaskError("news", ErrorResources.LoadAudiosErrorEmpty);
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
                OnTaskError("news", ErrorResources.LoadAudiosErrorCommon);
            }

            IsWorking = false;
            OnTaskFinished("news");
        }
开发者ID:kostyatab,项目名称:meridian,代码行数:65,代码来源:MusicViewModel.cs


注:本文中的System.Collections.ObservableCollection.IsNullOrEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。