how is async() => await function() non-blocking but just function() is blocking. what changes.
This commit is contained in:
parent
d9295de186
commit
c324cabd88
|
@ -1,6 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="AForge" publicKeyToken="c1db6ff4eaa06aeb" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="AForge.Math" publicKeyToken="abba2e25397ee8c9" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using AForge.Imaging.Filters;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
@ -226,13 +227,16 @@ namespace paperangapp {
|
|||
}
|
||||
string fn=r.FileName;
|
||||
r.Dispose();
|
||||
//I would love to know how spawning this in another thread via Task.Run((lambda)) and waiting for it to finish via `await`
|
||||
// is non-blocking, while simply running the code here is blocking.
|
||||
//someone who is good at threading please help my family is dying
|
||||
Bitmap bmg = await Task.Run(() => {
|
||||
logger.Debug($"Loading image '{fn}' for print");
|
||||
Image _=Image.FromFile(fn);
|
||||
logger.Debug($"Loaded image '{fn}'");
|
||||
logger.Debug("Disposed of dialog");
|
||||
Bitmap bimg=new Bitmap(_, mmj.Printer.LineWidth*8,
|
||||
(int)(mmj.Printer.LineWidth*8*((double)_.Height/_.Width)));
|
||||
(int)(mmj.Printer.LineWidth*8*((double)_.Height/_.Width)));
|
||||
logger.Debug("Loaded image as Bitmap");
|
||||
_.Dispose();
|
||||
logger.Debug("Disposed of Image");
|
||||
|
@ -244,13 +248,10 @@ namespace paperangapp {
|
|||
private async Task PrintBitmap(Bitmap bimg, bool dither = true) {
|
||||
if(dither) {
|
||||
logger.Trace("Dithering input bitmap");
|
||||
bimg = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.Y.Apply(bimg);
|
||||
AForge.Imaging.Filters.OrderedDithering f = new
|
||||
AForge.Imaging.Filters.OrderedDithering(bayer4);
|
||||
//f.FormatTranslations.Clear();
|
||||
//f.FormatTranslations[PixelFormat.Format1bppIndexed] = PixelFormat.Format1bppIndexed;
|
||||
bimg = Grayscale.CommonAlgorithms.Y.Apply(bimg);
|
||||
OrderedDithering f = new
|
||||
OrderedDithering(bayer4);
|
||||
bimg = f.Apply(bimg);
|
||||
//bimg = new Accord.Imaging.Filters.BayerDithering().Apply(bimg);
|
||||
logger.Debug("Dithered Bitmap");
|
||||
}
|
||||
bimg = CopyToBpp(bimg);
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>true</IsWebBootstrapper>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<PublishUrl>c:\swdep\paperang\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Web</InstallFrom>
|
||||
|
@ -28,13 +30,11 @@
|
|||
<InstallUrl>https://swdist.ext.maff.scot/paperang/</InstallUrl>
|
||||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>publish.htm</WebPage>
|
||||
<ApplicationRevision>5</ApplicationRevision>
|
||||
<ApplicationRevision>6</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
|
Loading…
Reference in New Issue