muratboy31 Posted October 13, 2015 Share Posted October 13, 2015 Merhaba, ImageListBox a itemleri yüklerken çok üzün süre bekliyorum (burada bahsettiğim binlerce item) bunu nasıl yapmalıyım ? En mantıklı yol nedir ? Ayrıca yüklemeyi hızlandırmak mümkün müdür ? Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 13, 2015 Share Posted October 13, 2015 benzer bir işle bende uğraşıyorum, resimleri yerel ağdan çekiyorum, 1500 civarı resim. GalleryControl kullandım, çok kasıyor.ImageListView'e backgroundworker ile yükleyince performans gayet iyi ama, ram şişmesi de olmuyor. GalleryControl 1 GB'ın üzerinde ram kullanıyor. BackGroundWorker ile bir deneyin derim. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 13, 2015 Author Share Posted October 13, 2015 onu denedim de aşağıdaki hatayı verdi ; Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 13, 2015 Share Posted October 13, 2015 public Form1() { InitializeComponents(); } yazan yere şunu ekleyin: public Giris() { CheckForIllegalCrossThreadCalls = false; InitializeComponent(); } Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 13, 2015 Author Share Posted October 13, 2015 yemedi, 10.000 kayıt ekledim denemek için, ama açmıyor program kitleniyor... Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 14, 2015 Editor Share Posted October 14, 2015 CheckForIllegalCrossThreadCalls = false; Task t1 = new Task.Factory.StartNew(() => { /*listboxadd*/ } ); Bu kodu bi denermisiniz. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 Aşağıdaki hatayı verdi ; Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 14, 2015 Editor Share Posted October 14, 2015 .NetFramework 4.5 mi seçili projede yoksa daha alt sürümümü. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 4.5 seçili durumda. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 14, 2015 Editor Share Posted October 14, 2015 using kısmında System.Threading ve System.Threading.Tasks eklimi. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 (edited) bu şekilde çalışıyor ancak, çok yavaş... Task.Factory.StartNew(() => {listBox.Items.Add(new ImageListBoxItem(nVal, "", photoList.Images.IndexOfKey(r.EmployeeID.ToString()), r.EmployeeID)); }); sistemde 776 kayıt bulunuyor ! Edited October 14, 2015 by muratboy31 Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 14, 2015 Editor Share Posted October 14, 2015 Ağdan oldugu için yavaş olacaktr. Eğer dosya ile ilgili bilgi çekiyorsanız. Şayet ağdan çekiyorsanız. Ağdaki isim yerine IP kullanın. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 (edited) Background worker ile çalışıyor ama yinede uzun sürüyor yüklemesi, acaba itemleri tek tek nasıl eklerim, yane hepsinin eklenmesini beklemesin ekleneni göstersin listede... 760 item 5 daikada yüklendi :) Edited October 14, 2015 by muratboy31 Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 14, 2015 Editor Share Posted October 14, 2015 (edited) listBox1.BeginUpdate(); listbox a ekleme kodları listBox1.EndUpdate(); şekline bi denermisiniz. Şuan o kaar çok dosyam olmadıgı için deneme imkanım yyok. Yada listbox ekleme kodlari listBox1.Update(); şeklindede deneyebilirsiniz. Edited October 14, 2015 by pairs Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 evet hız sorunu çözüldü gibi imageları bmp olarak içeri alınca 10 saniyede açıldı... Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 14, 2015 Share Posted October 14, 2015 izlediğin yolu buraya da yazar mısın? bakalım bizim e işimize yarar belki. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 14, 2015 Author Share Posted October 14, 2015 resimleri daha önce farklı formatta alıyordum ama bmp yapınca convert etmek zorunda kalmadığı için arada dağlar fark etti ; ayrıca backgroundWorker kullanacaksanız, runtime oluşturduğunuz objeleri invoke etmeniz gerekiyor... aşağıda örneği var... private void GetImages() { string path = @"Images"; string[] filter = { ".bmp" }; DirectoryInfo directoryInfo = new DirectoryInfo(path); FileInfo[] fileInfo = directoryInfo.GetFiles(); ArrayList arrayList = new ArrayList(); foreach (FileInfo fi in fileInfo) foreach (string s in filter) if (s == fi.Extension) arrayList.Add(fi.FullName); for (int i = 0; i < arrayList.Count; i++) { Image img = Image.FromFile(arrayList[i].ToString()); photoList.Images.Add(Path.GetFileNameWithoutExtension(arrayList[i].ToString()), img); } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Employees(); try { mycon.ConnectionString = Connect; mycon.Open(); mycommand.Connection = mycon; mycommand.CommandText = "sp_List_Offices"; mycommand.CommandType = CommandType.StoredProcedure; mycommand.ExecuteNonQuery(); using (SqlDataReader rdr = mycommand.ExecuteReader()) { while (rdr.Read()) { int L_OfficeID = rdr.GetInt32(0); string L_OfficeName = rdr.GetString(1); string L_OfficeCode = rdr.GetString(2); XtraTabPage tab = new XtraTabPage() { Text = L_OfficeName }; Invoke((MethodInvoker)delegate { xtraTabControl1.TabPages.Add(tab); }); ImageListBoxControl listBox = new ImageListBoxControl() { Name = "lb_Employee_" + Convert.ToString(L_OfficeID) }; listBox.Dock = DockStyle.Fill; listBox.ItemHeight = 40; listBox.ImageList = photoList; listBox.MouseClick += new MouseEventHandler(listBox_MouseClick); var result = L_Employee.Where(a => a.OfficeID == L_OfficeID); foreach (var r in result) { string nVal = r.Name + " " + r.Surname + "\r\n" + r.Title; Invoke((MethodInvoker)delegate { listBox.Items.Add(new ImageListBoxItem(nVal, "", photoList.Images.IndexOfKey(r.EmployeeID.ToString()), r.EmployeeID)); }); } Invoke((MethodInvoker)delegate { tab.Controls.Add(listBox); }); } rdr.Close(); } } catch (Exception a) { MessageBox.Show(Convert.ToString(a)); } finally { mycon.Close(); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.