Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

911914 - Add samples for Multithreading and ThreadSafety #144

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions FAQ/Multithreading/.NET/Multithreading/Multithreading.sln
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Empty file.
58 changes: 58 additions & 0 deletions FAQ/Multithreading/.NET/Multithreading/Multithreading/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
1 change: 1 addition & 0 deletions FAQ/Multithreading/.NET/Multithreading/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Does XlsIO library support multithreading and thread-safe?
Loading