diff --git a/FAQ/Multithreading/.NET/Multithreading/Multithreading.sln b/FAQ/Multithreading/.NET/Multithreading/Multithreading.sln new file mode 100644 index 00000000..b0303033 --- /dev/null +++ b/FAQ/Multithreading/.NET/Multithreading/Multithreading.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34310.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreading", "Multithreading\Multithreading.csproj", "{FF011E2F-22A0-4FE9-927E-E19D6943A39F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF011E2F-22A0-4FE9-927E-E19D6943A39F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF011E2F-22A0-4FE9-927E-E19D6943A39F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF011E2F-22A0-4FE9-927E-E19D6943A39F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF011E2F-22A0-4FE9-927E-E19D6943A39F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3FF7195C-8AA0-4979-9884-45A22FE9BCE4} + EndGlobalSection +EndGlobal diff --git a/FAQ/Multithreading/.NET/Multithreading/Multithreading/Data/InputTemplate.xlsx b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Data/InputTemplate.xlsx new file mode 100644 index 00000000..39d8d2cc Binary files /dev/null and b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Data/InputTemplate.xlsx differ diff --git a/FAQ/Multithreading/.NET/Multithreading/Multithreading/Multithreading.csproj b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Multithreading.csproj new file mode 100644 index 00000000..fe74e2d4 --- /dev/null +++ b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Multithreading.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + + diff --git a/FAQ/Multithreading/.NET/Multithreading/Multithreading/Output/.gitkeep b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Multithreading/.NET/Multithreading/Multithreading/Program.cs b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Program.cs new file mode 100644 index 00000000..e202b178 --- /dev/null +++ b/FAQ/Multithreading/.NET/Multithreading/Multithreading/Program.cs @@ -0,0 +1,58 @@ +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; +using Syncfusion.Pdf; + +namespace Multithreading +{ + class MultiThreading + { + //Defines the number of threads to be created + private const int ThreadCount = 1000; + public static void Main() + { + //Create an array of threads based on the ThreadCount + Thread[] threads = new Thread[ThreadCount]; + for (int i = 0; i < ThreadCount; i++) + { + threads[i] = new Thread(ReadEditConvertExcel); + threads[i].Start(); + } + + //Ensure all threads complete by calling Join on each thread + for (int i = 0; i < ThreadCount; i++) + { + threads[i].Join(); + } + } + + //Method to convert Excel to PDF + static void ReadEditConvertExcel() + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2016; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + inputStream.Close(); + IWorksheet sheet = workbook.Worksheets[0]; + + //Add text, formula, and number in the worksheet + sheet.Range["A1"].Text = "Hello World" + DateTime.Now; + Console.WriteLine(sheet.Range["A1"].Text); + sheet.Range["A2"].Formula = "=Now()"; + sheet.Range["A3"].Number = 12345; + + //Convert the Excel workbook to PDF + XlsIORenderer xlsIORenderer = new XlsIORenderer(); + PdfDocument pdfDocument = xlsIORenderer.ConvertToPDF(workbook); + + //Save the PDF document + MemoryStream fileStream = new MemoryStream(); + pdfDocument.Save(fileStream); + fileStream.Close(); + pdfDocument.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/FAQ/Multithreading/.NET/Multithreading/README.md b/FAQ/Multithreading/.NET/Multithreading/README.md new file mode 100644 index 00000000..eb8b3bcc --- /dev/null +++ b/FAQ/Multithreading/.NET/Multithreading/README.md @@ -0,0 +1 @@ +# Does XlsIO library support multithreading and thread-safe?