Exemple #1
0
 public static bool Contain(this BindableCollection <ProcComboboxItem> data, ProcComboboxItem tar)
 {
     foreach (var item in data)
     {
         if (item.proc.Id == tar.proc.Id)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
        public async Task GetProcessListAsync(BindableCollection <ProcComboboxItem> data)
        {
            await Task.Run(() =>
            {
                BindableCollection <ProcComboboxItem> tmpCollection = new BindableCollection <ProcComboboxItem>();

                foreach (Process proc in ProcessEnumerable())
                {
                    try
                    {
                        var item = new ProcComboboxItem()
                        {
                            proc  = proc,
                            Title = proc.MainWindowTitle,
                            Icon  = Utils.PEIcon2BitmapImage(proc.GetMainModuleFileName())
                        };
                        tmpCollection.Add(item);
                        if (data.Contain(item))
                        {
                            continue;
                        }
                        else
                        {
                            data.Add(item);
                        }
                    }
                    catch (Win32Exception ex)
                    {
                        // Casue by `GetMainModuleFileName()`
                        // Access Denied. 32bit -> 64bit module
                        log.Warn(ex.Message);
                    }
                }
                foreach (var i in data.ToList())
                {
                    if (!tmpCollection.Contain(i))
                    {
                        data.Remove(i);
                    }
                }
            }).ConfigureAwait(false);
        }