public MainWindow() { InitializeComponent(); _store = new SQLiteStore(store_CreateSchema, 4); _wpfProxy = new WPFProxy(); itemsDataGrid.ItemsSource = _store.GetTable("Files").DefaultView; }
private void btnLoadList_Click(object sender, RoutedEventArgs e) { DataTable items = _store.GetTable("Files"); foreach (DataRow row in items.Rows) { row.Delete(); } int fileCnt = items.Rows.Count; DataTable attribs = _store.GetTable("Attributes"); foreach (DataRow row in attribs.Rows) { row.Delete(); } _store.Update("Attributes"); _store.Update("Files"); List <Task> tasks = new List <Task>(); Random rnd = new Random(); Task mainTask = Task.Factory.StartNew(() => { foreach (string fileName in Directory.EnumerateFiles(@"D:\Andy\Art", "*.jpg", SearchOption.AllDirectories)) { Thread.Sleep(rnd.Next(2, 5) * 100); FileInfo info = new FileInfo(fileName); DataRow row = items.NewRow(); row["FileName"] = info.Name; row["filepath"] = info.DirectoryName; row["FileSize"] = info.Length; row["image_size"] = ""; row["pixel_format"] = ""; row["State"] = ""; _wpfProxy.Invoke((Action <DataRow, FileAttributes>)((r1, attributes) => { items.Rows.Add(r1); //filesAdapter.Update(new DataRow[] {r1}); // store row and get Id foreach (int attrVal in Enum.GetValues(typeof(FileAttributes))) { if (((FileAttributes)attrVal & attributes) != 0) { DataRow attrRow = attribs.NewRow(); attrRow["Name"] = ((FileAttributes)attrVal).ToString(); attrRow["Value"] = 1; attrRow["FileId"] = r1["Id"]; attribs.Rows.Add(attrRow); } } }), row, info.Attributes); Action <object> action = (obj) => { Thread.Sleep(rnd.Next(3, 10) * 100); DataRow r = (DataRow)obj; string fileName1 = System.IO.Path.Combine((string)r["filepath"], (string)r["FileName"]); using (var image = new System.Drawing.Bitmap(fileName1)) { r.BeginEdit(); r["image_size"] = image.Size.ToString(); r["pixel_format"] = image.PixelFormat.ToString(); r["State"] = "Done"; _wpfProxy.Invoke((Action <DataRow>)((r1) => r1.EndEdit()), r); } }; tasks.Add(Task.Factory.StartNew(action, row)); if (items.Rows.Count - fileCnt > 20) { break; } } }); }