-
Notifications
You must be signed in to change notification settings - Fork 5
941854: UG Documentation for multi threading and thread safety in PdfToImageConverter #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28fd8ea
Multithreading using tasks
KrithikaGanesan 7737ad5
Multithreading using parallel process
KrithikaGanesan bc441ea
Multithreading
KrithikaGanesan 2a0430c
941854: UG Documentation for multi threading and thread safety in Pdf…
KrithikaGanesan 06b818b
941854: UG Documentation for multi threading and thread safety in Pdf…
KrithikaGanesan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+205 KB
PDF-to-image/Multithreading-using-parallel-process-in-.NET/Data/Input.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
...ultithreading-using-parallel-process-in-.NET/Multithreading-using-parallel-process.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Multithreading_using_parallel_process</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
...e/Multithreading-using-parallel-process-in-.NET/Multithreading-using-parallel-process.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.13.35818.85 d17.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreading-using-parallel-process", "Multithreading-using-parallel-process.csproj", "{1989562F-B2D5-4030-B4B5-7CE03A727A4F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1989562F-B2D5-4030-B4B5-7CE03A727A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1989562F-B2D5-4030-B4B5-7CE03A727A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1989562F-B2D5-4030-B4B5-7CE03A727A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1989562F-B2D5-4030-B4B5-7CE03A727A4F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3C50F3BF-01C8-4496-AB89-EE451C32138B} | ||
EndGlobalSection | ||
EndGlobal |
43 changes: 43 additions & 0 deletions
43
PDF-to-image/Multithreading-using-parallel-process-in-.NET/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Syncfusion.PdfToImageConverter; | ||
|
||
namespace Multithreading_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 PDF document, one document on each thread. | ||
ConvertPdfToImage(count); | ||
Console.WriteLine("Task {0} is done", count); | ||
}); | ||
} | ||
//Open and save a PDF document using multi-threading. | ||
static void ConvertPdfToImage(int count) | ||
{ | ||
using (FileStream inputStream = new FileStream(@"../../../Data/Input.pdf", FileMode.Open, FileAccess.Read)) | ||
{ | ||
//Load an existing PDF document. | ||
using (PdfToImageConverter imageConverter = new PdfToImageConverter(inputStream)) | ||
{ | ||
Stream outputStream = imageConverter.Convert(0, false, false); | ||
|
||
//Rewind the stream position to the beginning before copying. | ||
outputStream.Position = 0; | ||
|
||
//Create file stream. | ||
using (FileStream outputFileStream = new FileStream("Output" + count + ".jpeg", FileMode.Create, FileAccess.Write)) | ||
{ | ||
//Save the image to file stream. | ||
outputStream.CopyTo(outputFileStream); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
PDF-to-image/Multithreading-using-tasks-in-.NET/Multithreading-using-tasks.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Multithreading_using_tasks</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
PDF-to-image/Multithreading-using-tasks-in-.NET/Multithreading-using-tasks.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.13.35818.85 d17.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multithreading-using-tasks", "Multithreading-using-tasks.csproj", "{4359DB27-1E8B-4B21-AE6B-7A5E3AE58022}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{4359DB27-1E8B-4B21-AE6B-7A5E3AE58022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4359DB27-1E8B-4B21-AE6B-7A5E3AE58022}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4359DB27-1E8B-4B21-AE6B-7A5E3AE58022}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4359DB27-1E8B-4B21-AE6B-7A5E3AE58022}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4229D954-1DCB-4D09-99C5-07520C20B09E} | ||
EndGlobalSection | ||
EndGlobal |
Empty file.
44 changes: 44 additions & 0 deletions
44
PDF-to-image/Multithreading-using-tasks-in-.NET/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Syncfusion.PdfToImageConverter; | ||
|
||
namespace Multithreading_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(() => ConvertPdfToImage()); | ||
} | ||
//Ensure all tasks complete by waiting on each task. | ||
await Task.WhenAll(tasks); | ||
} | ||
|
||
//Open a PDF document and save image using multi-threading. | ||
static void ConvertPdfToImage() | ||
{ | ||
using (FileStream inputStream = new FileStream(@"../../../Data/Input.pdf", FileMode.Open, FileAccess.Read)) | ||
{ | ||
//Load an existing PDF document. | ||
using (PdfToImageConverter imageConverter = new PdfToImageConverter(inputStream)) | ||
{ | ||
Stream outputStream = imageConverter.Convert(0, false, false); | ||
|
||
//Rewind the stream position to the beginning before copying. | ||
outputStream.Position = 0; | ||
|
||
//Create file stream. | ||
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output/Output" + Guid.NewGuid().ToString() + ".jpeg"), FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
//Save the image to file stream. | ||
outputStream.CopyTo(outputFileStream); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.