Skip to content

Commit b49a58e

Browse files
Add example for multithreading
1 parent cbace54 commit b49a58e

File tree

20 files changed

+371
-0
lines changed

20 files changed

+371
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-parallel-process", "Multithreaded-using-parallel-process\Multithreaded-using-parallel-process.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Multithreaded_using_parallel_process</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Input.pptx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Syncfusion.Presentation;
2+
using Syncfusion.Pdf;
3+
using System;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Syncfusion.PresentationRenderer;
7+
8+
namespace Multithreaded_using_parallel_process
9+
{
10+
class MultiThreading
11+
{
12+
static void Main(string[] args)
13+
{
14+
//Indicates the number of threads to be create.
15+
int limit = 5;
16+
Console.WriteLine("Parallel For Loop");
17+
Parallel.For(0, limit, count =>
18+
{
19+
Console.WriteLine("Task {0} started", count);
20+
//Convert multiple presentations, one PPT on each thread.
21+
ConvertPowerPointToPDF(count);
22+
Console.WriteLine("Task {0} is done", count);
23+
});
24+
}
25+
//Convert a Powerpoint presentation to PDF using multi-threading.
26+
static void ConvertPowerPointToPDF(int count)
27+
{
28+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
29+
{
30+
//Load an existing PowerPoint presentation.
31+
using (IPresentation presentation = Presentation.Open(inputStream))
32+
{
33+
//Convert PowerPoint presentation to PDF.
34+
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
35+
{
36+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + count + ".pdf"), FileMode.Create, FileAccess.Write))
37+
{
38+
//Save the PDF document.
39+
pdfDocument.Save(outputFileStream);
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-tasks", "Multithreaded-using-tasks\Multithreaded-using-tasks.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Multithreaded_using_tasks</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Input.pptx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Syncfusion.Presentation;
2+
using Syncfusion.Pdf;
3+
using System;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Syncfusion.PresentationRenderer;
7+
8+
namespace Multithreaded_using_tasks
9+
{
10+
class MultiThreading
11+
{
12+
//Indicates the number of threads to be create.
13+
private const int TaskCount = 1000;
14+
public static async Task Main()
15+
{
16+
//Create an array of tasks based on the TaskCount.
17+
Task[] tasks = new Task[TaskCount];
18+
for (int i = 0; i < TaskCount; i++)
19+
{
20+
tasks[i] = Task.Run(() => ConvertPowerPointToPDF());
21+
}
22+
//Ensure all tasks complete by waiting on each task.
23+
await Task.WhenAll(tasks);
24+
}
25+
26+
//Convert a Powerpoint presentation to PDF using multi-threading.
27+
static void ConvertPowerPointToPDF()
28+
{
29+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
30+
{
31+
//Load an existing PowerPoint presentation.
32+
using (IPresentation presentation = Presentation.Open(inputStream))
33+
{
34+
//Convert PowerPoint presentation to PDF.
35+
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
36+
{
37+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + Guid.NewGuid().ToString() + ".pdf"), FileMode.Create, FileAccess.Write))
38+
{
39+
//Save the PDF document.
40+
pdfDocument.Save(outputFileStream);
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)