Skip to content

Commit

Permalink
Merge pull request #104 from Suriya-Balamurugan/master
Browse files Browse the repository at this point in the history
Added example for multithreading
  • Loading branch information
MohanaselvamJothi authored Dec 10, 2024
2 parents cbace54 + b49a58e commit 31421e0
Show file tree
Hide file tree
Showing 20 changed files with 371 additions and 0 deletions.
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 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-parallel-process", "Multithreaded-using-parallel-process\Multithreaded-using-parallel-process.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Multithreaded_using_parallel_process</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Syncfusion.Presentation;
using Syncfusion.Pdf;
using System;
using System.IO;
using System.Threading.Tasks;
using Syncfusion.PresentationRenderer;

namespace Multithreaded_using_parallel_process
{
class MultiThreading
{
static void Main(string[] args)
{
//Indicates the number of threads to be create.
int limit = 5;
Console.WriteLine("Parallel For Loop");
Parallel.For(0, limit, count =>
{
Console.WriteLine("Task {0} started", count);
//Convert multiple presentations, one PPT on each thread.
ConvertPowerPointToPDF(count);
Console.WriteLine("Task {0} is done", count);
});
}
//Convert a Powerpoint presentation to PDF using multi-threading.
static void ConvertPowerPointToPDF(int count)
{
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
//Load an existing PowerPoint presentation.
using (IPresentation presentation = Presentation.Open(inputStream))
{
//Convert PowerPoint presentation to PDF.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
{
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + count + ".pdf"), FileMode.Create, FileAccess.Write))
{
//Save the PDF document.
pdfDocument.Save(outputFileStream);
}
}
}
}
}
}
}
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 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-tasks", "Multithreaded-using-tasks\Multithreaded-using-tasks.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Multithreaded_using_tasks</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Syncfusion.Presentation;
using Syncfusion.Pdf;
using System;
using System.IO;
using System.Threading.Tasks;
using Syncfusion.PresentationRenderer;

namespace Multithreaded_using_tasks
{
class MultiThreading
{
//Indicates the number of threads to be create.
private const int TaskCount = 1000;
public static async Task Main()
{
//Create an array of tasks based on the TaskCount.
Task[] tasks = new Task[TaskCount];
for (int i = 0; i < TaskCount; i++)
{
tasks[i] = Task.Run(() => ConvertPowerPointToPDF());
}
//Ensure all tasks complete by waiting on each task.
await Task.WhenAll(tasks);
}

//Convert a Powerpoint presentation to PDF using multi-threading.
static void ConvertPowerPointToPDF()
{
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
//Load an existing PowerPoint presentation.
using (IPresentation presentation = Presentation.Open(inputStream))
{
//Convert PowerPoint presentation to PDF.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation))
{
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + Guid.NewGuid().ToString() + ".pdf"), FileMode.Create, FileAccess.Write))
{
//Save the PDF document.
pdfDocument.Save(outputFileStream);
}
}
}
}
}
}
}
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 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-parallel-process", "Multithreaded-using-parallel-process\Multithreaded-using-parallel-process.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Multithreaded_using_parallel_process</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Syncfusion.Presentation;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Multithreaded_using_parallel_process
{
class MultiThreading
{
static void Main(string[] args)
{
//Indicates the number of threads to be create.
int limit = 5;
Console.WriteLine("Parallel For Loop");
Parallel.For(0, limit, count =>
{
Console.WriteLine("Task {0} started", count);
//Create multiple presentations, one PPT on each thread.
OpenAndSavePresentation(count);
Console.WriteLine("Task {0} is done", count);
});
}
//Open and save a Powerpoint presentation using multi-threading.
static void OpenAndSavePresentation(int count)
{
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
//Load an existing PowerPoint presentation.
using (IPresentation presentation = Presentation.Open(inputStream))
{
//Add a slide of TitleAndContent type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleAndContent);
//Save the presentation in the desired format.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + count + ".pptx"), FileMode.Create, FileAccess.Write))
{
presentation.Save(outputFileStream);
}
}
}
}
}

}
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 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreaded-using-tasks", "Multithreaded-using-tasks\Multithreaded-using-tasks.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Multithreaded_using_tasks</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Syncfusion.Presentation;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Multithreaded_using_tasks
{
class MultiThreading
{
//Indicates the number of threads to be create.
private const int TaskCount = 1000;
public static async Task Main()
{
//Create an array of tasks based on the TaskCount.
Task[] tasks = new Task[TaskCount];
for (int i = 0; i < TaskCount; i++)
{
tasks[i] = Task.Run(() => OpenAndSavePresentation());
}
//Ensure all tasks complete by waiting on each task.
await Task.WhenAll(tasks);
}

//Open and save a Powerpoint presentation using multi-threading.
static void OpenAndSavePresentation()
{
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
{
//Load an existing PowerPoint presentation.
using (IPresentation presentation = Presentation.Open(inputStream))
{
//Add a slide of TitleAndContent type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleAndContent);
//Save the presentation in the desired format.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + Guid.NewGuid().ToString() + ".pptx"), FileMode.Create, FileAccess.Write))
{
presentation.Save(outputFileStream);
}
}
}
}
}
}

0 comments on commit 31421e0

Please sign in to comment.