  | 
              
	              
	                
  
    |   | 
   
  
    
        
        C# เอาโค๊ดค้นหาเพลงซ้ำใน extreme karaoke มาให้ช่วยแก้ครับเหมือนมันยังช้าอยู่     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ผมดึงข้อมูลมาลงใน DataGridView ก่อนแล้วค่อยค้นหาทีละแถวที่ผมทำอยู่คือ 
สร้าง Thread มา 10 Thread สำหรับ CheckFileDup โดยเอา  
โดยค้นทีละ DataGridView.RowCount/10 
เพลงทั้ง NCN และ EMK 1.5 ล้านกว่าเพลง ใช้เวลาค้นแล้วลบไฟล์ซ้ำ 12 ชั่วโมงกว่า 
ก็เลยอยากให้ดูหน่อยครับว่ามีวิธีทำให้เร็วกว่านี้ไม๊ 
อีกอย่างผมต้องการให้ลบไฟล์แล้วก็ลบข้อมูลใน database ด้วยแต่ที่เคยทำมันจะช้าตอนลบข้อมูลใน database ผมก็เลยไม่ลบ 
 
Code (C#) 
namespace MIDI_System
{
    public static class CheckFileDupSetting
    {
        public static string FolKara = "";
        public static Label labelInvoke;
        public static int sngDel = 0;
        public static string FolDel = "";
        public static DataGridView GridView;
        public static int SongCheck = 0;
public static DataTable GetDataTableDBF(string _Path)
        {
            string PathData = "";
            if (_Path.ToUpper().EndsWith("\\DATA"))
            {
                PathData = _Path.ToUpper();
            }
            else
            {
                PathData = _Path.ToUpper() + "\\DATA";
            }
            string ConnectionString = "Dsn=dBASE Files;dbq=" + PathData.ToUpper() + ";defaultdir=" + PathData.ToUpper() + ";driverid=533;maxbuffersize=2048;pagetimeout=5";
            System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(ConnectionString);
            conn.Open();
            string strQuery = "SELECT CODE,TYPE,SUB_TYPE,ARTIST + TITLE as SongName FROM SONG order by ARTIST + TITLE";
            System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(strQuery, conn);
            System.Data.DataSet ds = new System.Data.DataSet();
            adapter.Fill(ds);
            return ds.Tables[0];
        }
        public static void DelFile(string _FileName)
        {
            try { System.IO.File.Delete(_FileName); }
            catch
            {
                try
                {
                    System.IO.File.Move(_FileName, FolDel + "\\" + String.Format("{0:ddMMyyyyHHmmss}", DateTime.Now) + System.IO.Path.GetFileName(_FileName));
                }
                catch { }
            }
        }
    }
    public class CheckFileDup
    {
        System.Threading.Thread thd;
        int _Min;
        int _Max;
        public CheckFileDup(int min, int max)
        {
            _Min = min; _Max = max;
        }
        public void RunCheck()
        {
            thd = new System.Threading.Thread(new System.Threading.ThreadStart(CheckFile));
            thd.Start();
        }
        private void CheckFile()
        {
            string cri = "";
            for (int i = _Min; i <= _Max; i++)
            {
                if (CheckFileDupSetting.GridView[3, i].Value.ToString().Trim().Replace(" ", "").ToUpper() != cri)
                {
                    cri = CheckFileDupSetting.GridView[3, i].Value.ToString().Trim().Replace(" ", "").ToUpper();
                }
                else
                {
                    CheckFileDupSetting.sngDel++;
                    if (CheckFileDupSetting.GridView[2, i].Value.ToString() == "EMK")
                    {
                        CheckFileDupSetting.DelFile(CheckFileDupSetting.FolKara + "\\SONGS\\MIDI\\EMK\\" + CheckFileDupSetting.GridView[0, i].Value.ToString().Substring(0, 1) + "\\" + CheckFileDupSetting.GridView[0, i].Value.ToString() + ".emk");
                    }
                    else if (CheckFileDupSetting.GridView[2, i].Value.ToString() == "NCN")
                    {
                        CheckFileDupSetting.DelFile(CheckFileDupSetting.FolKara + "\\SONGS\\MIDI\\NCN\\Lyrics\\" + CheckFileDupSetting.GridView[0, i].Value.ToString().Substring(0, 1) + "\\" + CheckFileDupSetting.GridView[0, i].Value.ToString() + ".lyr");
                        CheckFileDupSetting.DelFile(CheckFileDupSetting.FolKara + "\\SONGS\\MIDI\\NCN\\Cursor\\" + CheckFileDupSetting.GridView[0, i].Value.ToString().Substring(0, 1) + "\\" + CheckFileDupSetting.GridView[0, i].Value.ToString() + ".cur");
                        CheckFileDupSetting.DelFile(CheckFileDupSetting.FolKara + "\\SONGS\\MIDI\\NCN\\Song\\" + CheckFileDupSetting.GridView[0, i].Value.ToString().Substring(0, 1) + "\\" + CheckFileDupSetting.GridView[0, i].Value.ToString() + ".mid");
                    }
                }
                CheckFileDupSetting.SongCheck = CheckFileDupSetting.SongCheck + (i - _Min);
                CheckFileDupSetting.labelInvoke.Invoke(new Action(() => { CheckFileDupSetting.labelInvoke.Text = "Song All:" + (CheckFileDupSetting.GridView.RowCount - 1) + " Song Check:" + CheckFileDupSetting.SongCheck + " Song Delete:" + CheckFileDupSetting.sngDel + " Cri:" + cri; }));
                System.Threading.Thread.Sleep(5);
            }
        }
    }
}
 
 
  Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x), Windows               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2014-11-12 16:35:10 | 
                      By :
                          lamaka.tor | 
                      View :
                          7418 | 
                      Reply :
                          37 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
                 |