Skip to content

Commit 2041a31

Browse files
committed
Settings
Fixed crash when closing and a thumbnail thread is still running.
1 parent f7c6560 commit 2041a31

4 files changed

Lines changed: 95 additions & 14 deletions

File tree

ImageTagger/Properties/Settings.Designer.cs

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
3-
<Profiles>
4-
<Profile Name="(Default)" />
5-
</Profiles>
6-
<Settings />
7-
</SettingsFile>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ImageTagger.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="LastPath" Type="System.String" Scope="User">
6+
<Value Profile="(Default)" />
7+
</Setting>
8+
<Setting Name="StandardShortcuts" Type="System.Boolean" Scope="User">
9+
<Value Profile="(Default)">True</Value>
10+
</Setting>
11+
<Setting Name="ImageSize" Type="System.Int32" Scope="User">
12+
<Value Profile="(Default)">256</Value>
13+
</Setting>
14+
</Settings>
15+
</SettingsFile>

ImageTagger/app.config

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="ImageTagger.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup><userSettings>
9+
<ImageTagger.Properties.Settings>
10+
<setting name="LastPath" serializeAs="String">
11+
<value />
12+
</setting>
13+
<setting name="StandardShortcuts" serializeAs="String">
14+
<value>True</value>
15+
</setting>
16+
<setting name="ImageSize" serializeAs="String">
17+
<value>256</value>
18+
</setting>
19+
</ImageTagger.Properties.Settings>
20+
</userSettings>
21+
</configuration>

ImageTagger/frmTagger.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ public partial class frmTagger : Form
2727
private List<UITagGroup> tagGroups = new List<UITagGroup>();
2828
private UITagGroup selectedGroup;
2929

30+
private Properties.Settings Settings;
31+
3032
public frmTagger()
3133
{
3234
InitializeComponent();
3335

36+
37+
Settings = new Properties.Settings();
38+
txtPath.Text = Settings.LastPath;
39+
standardShortcuts.Checked = Settings.StandardShortcuts;
40+
imageSize = Settings.ImageSize;
41+
3442
lst.TileSize = new Size(imageSize, imageSize);
3543

3644
ChangeTagLayout(standardShortcuts.Checked);
@@ -79,12 +87,15 @@ private void addGroup(UITagGroup group)
7987
private void frmTagger_Load(object sender, EventArgs e)
8088
{
8189
ActiveControl = txtPath;
90+
if (txtPath.Text != "")
91+
buttonLoad_Click(sender, e);
8292
}
8393

8494
private void frmTagger_FormClosing(object sender, FormClosingEventArgs e)
8595
{
8696
threadPool.Run = false;
8797
buttonSave_Click(sender, e);
98+
Settings.Save();
8899
}
89100

90101

@@ -96,6 +107,8 @@ private void buttonLoad_Click(object sender, EventArgs e)
96107
if (path.Length == 0 || !Directory.Exists(path))
97108
return;
98109

110+
Settings.LastPath = path;
111+
99112
lst.SuspendLayout();
100113
images.Clear();
101114
lst.Clear();
@@ -151,13 +164,18 @@ private void buttonLoad_Click(object sender, EventArgs e)
151164
thumb.Dispose();
152165
img.Dispose();
153166

154-
Invoke(new Action(() =>
167+
try
155168
{
156-
if (info.ListView != null)
157-
info.ListView.RedrawItems(info.Index, info.Index, false);
158-
else
159-
lst.Invalidate();
160-
}));
169+
Invoke(new Action(() =>
170+
{
171+
if (info.ListView != null)
172+
info.ListView.RedrawItems(info.Index, info.Index, false);
173+
else
174+
lst.Invalidate();
175+
}));
176+
}
177+
catch (Exception ex) when (ex is ObjectDisposedException || ex is InvalidAsynchronousStateException)
178+
{ }
161179
});
162180
}
163181

@@ -330,6 +348,7 @@ private void lst_MouseDoubleClick(object sender, MouseEventArgs e)
330348

331349
private void standardShortcuts_CheckedChanged(object sender, EventArgs e)
332350
{
351+
Settings.StandardShortcuts = standardShortcuts.Checked;
333352
ChangeTagLayout(standardShortcuts.Checked);
334353
}
335354

0 commit comments

Comments
 (0)