From ea64977098f3d9f513bee2dd4dd2a391de084488 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Tue, 16 Apr 2024 15:48:15 +0900 Subject: [PATCH] make the worker asynchronously --- .../Helper/CbpfExtractor.cs | 9 ++++- Catswords.DataType.Client/UserControl1.cs | 33 ++++++++++++++----- Catswords.DataType.Client/Worker.cs | 13 ++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Catswords.DataType.Client/Helper/CbpfExtractor.cs b/Catswords.DataType.Client/Helper/CbpfExtractor.cs index 374cdd3..97d37ae 100644 --- a/Catswords.DataType.Client/Helper/CbpfExtractor.cs +++ b/Catswords.DataType.Client/Helper/CbpfExtractor.cs @@ -1,7 +1,14 @@ namespace Catswords.DataType.Client.Helper { - internal class CbpfExtractor + public class CbpfExtractor { + private string FilePath; + + public CbpfExtractor(string filePath) + { + FilePath = filePath; + } + } } diff --git a/Catswords.DataType.Client/UserControl1.cs b/Catswords.DataType.Client/UserControl1.cs index aa95863..2a11b08 100644 --- a/Catswords.DataType.Client/UserControl1.cs +++ b/Catswords.DataType.Client/UserControl1.cs @@ -66,13 +66,8 @@ namespace Catswords.DataType.Client FileName = ""; } - // Extract - var worker = new Worker(this); - worker.FromFileExtension(); // Get data from file extension database - worker.FromAndroidManifest(); // Get data from Android manifest - worker.FromTimeline(); // Get data from timeline - worker.FromLinks(); // Get links from file - worker.FromExif(); // Get EXIF tags from file + // Run the worker + (new Worker(this)).Run(); } public string OpenFileDialog() @@ -93,12 +88,32 @@ namespace Catswords.DataType.Client public void AddIndicator(DateTime dt, string Description, int ImageIndex) { - listView1.Items.Add(new ListViewItem(new string[] { dt.ToString(), Description }, ImageIndex)); + if (listView1.InvokeRequired) { + listView1.Invoke(new MethodInvoker(delegate + { + listView1.Items.Add(new ListViewItem(new string[] { dt.ToString(), Description }, ImageIndex)); + })); + } + else + { + listView1.Items.Add(new ListViewItem(new string[] { dt.ToString(), Description }, ImageIndex)); + } + } public void ShowStatus(string status) { - textBox1.Text = status; + if (textBox1.InvokeRequired) + { + textBox1.Invoke(new MethodInvoker(delegate + { + textBox1.Text = status; + })); + } + else + { + textBox1.Text = status; + } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) diff --git a/Catswords.DataType.Client/Worker.cs b/Catswords.DataType.Client/Worker.cs index ceb6fa1..65cfca3 100644 --- a/Catswords.DataType.Client/Worker.cs +++ b/Catswords.DataType.Client/Worker.cs @@ -1,6 +1,7 @@ using Catswords.DataType.Client.Helper; using Catswords.DataType.Client.Model; using System; +using System.Threading.Tasks; namespace Catswords.DataType.Client { @@ -138,5 +139,17 @@ namespace Catswords.DataType.Client Parent.AddIndicator(DateTime.Now, $"{tag.Name} ({tag.Section}): {tag.Description}", 5); } } + + public void Run() + { + new Task(() => + { + FromFileExtension(); // Get data from file extension database + FromAndroidManifest(); // Get data from Android manifest + FromTimeline(); // Get data from timeline + FromLinks(); // Get links from file + FromExif(); // Get EXIF tags from file + }).Start(); + } } }