Skip to content

Commit a8640e4

Browse files
committed
update to 4.5 net framework and use async wait task, do not block application while doing replace job
1 parent 5f01063 commit a8640e4

16 files changed

+26
-4
lines changed

.vs/LFAR/v16/.suo

2.5 KB
Binary file not shown.
1.01 MB
Binary file not shown.

LFAR/Form1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LFAR/Form1.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using System.Linq;
88
using System.Text;
99
using System.Text.RegularExpressions;
10+
using System.Threading;
11+
using System.Threading.Tasks;
1012
using System.Windows.Forms;
1113
using System.Xml;
1214
using System.Xml.Linq;
@@ -185,7 +187,16 @@ private void buttonSelectPathOfFile(object sender, EventArgs e)
185187
}
186188
}
187189

188-
private void buttonDoReplaceJob_Click(object sender, EventArgs e)
190+
private async void buttonDoReplaceJob_Click(object sender, EventArgs e)
191+
{
192+
label1.Text = "Running task, please wait...";
193+
194+
int replacesCount = await Task.Run(() => DoReplaceJob(3000));
195+
196+
label1.Text = "Jobs finished: " + replacesCount + " replaces.";
197+
}
198+
199+
private int DoReplaceJob(int sleepTime)
189200
{
190201
int replacesCount = 0;
191202

@@ -219,11 +230,14 @@ private void buttonDoReplaceJob_Click(object sender, EventArgs e)
219230
if (replacesCount > 0)
220231
File.WriteAllText(pathOfFile, text);
221232
}
222-
label1.Text = "Jobs finished: "+ replacesCount + " replaces.";
223233
}
224234
}
225235
else
226236
MessageBox.Show("Please select a valid file!");
237+
238+
Thread.Sleep(sleepTime);
239+
240+
return replacesCount;
227241
}
228242
}
229243
}

LFAR/LFAR.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>WinExe</OutputType>
99
<RootNamespace>LFAR</RootNamespace>
1010
<AssemblyName>LFAR</AssemblyName>
11-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<Deterministic>true</Deterministic>
1414
<PublishUrl>publish\</PublishUrl>
@@ -26,6 +26,7 @@
2626
<IsWebBootstrapper>false</IsWebBootstrapper>
2727
<UseApplicationTrust>false</UseApplicationTrust>
2828
<BootstrapperEnabled>true</BootstrapperEnabled>
29+
<TargetFrameworkProfile />
2930
</PropertyGroup>
3031
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3132
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -36,6 +37,7 @@
3637
<DefineConstants>DEBUG;TRACE</DefineConstants>
3738
<ErrorReport>prompt</ErrorReport>
3839
<WarningLevel>4</WarningLevel>
40+
<Prefer32Bit>false</Prefer32Bit>
3941
</PropertyGroup>
4042
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4143
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -45,6 +47,7 @@
4547
<DefineConstants>TRACE</DefineConstants>
4648
<ErrorReport>prompt</ErrorReport>
4749
<WarningLevel>4</WarningLevel>
50+
<Prefer32Bit>false</Prefer32Bit>
4851
</PropertyGroup>
4952
<PropertyGroup>
5053
<ApplicationIcon>search.ico</ApplicationIcon>
@@ -82,6 +85,7 @@
8285
<DependentUpon>Resources.resx</DependentUpon>
8386
<DesignTime>True</DesignTime>
8487
</Compile>
88+
<None Include="app.config" />
8589
<None Include="Properties\Settings.settings">
8690
<Generator>SettingsSingleFileGenerator</Generator>
8791
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

LFAR/app.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
608 Bytes
Binary file not shown.
142 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)