Skip to content

Commit 6a6f4a9

Browse files
committed
fixed thread sync issue with async operation
1 parent ca27148 commit 6a6f4a9

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

SvgFileType/SvgFileType.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ private void GetInitialValues(out int viewportW, out int viewportH, out int ppi,
9999

100100
#region Events
101101

102-
private async void Dialog_OkClick(object sender, EventArgs e)
102+
private void Dialog_OkClick(object sender, EventArgs e)
103103
{
104-
pdnDocument = await Task.Run(DoImport, cts.Token)
105-
.ContinueWith(AfterImport)
106-
.ConfigureAwait(false);
104+
Task.Run(DoImport, cts.Token).ContinueWith(AfterImport);
107105
}
108106

109107
private void Dialog_FormClosing(object sender, FormClosingEventArgs e)
@@ -137,7 +135,7 @@ private DialogResult ShowMemoryWarningDialog(int layerCount)
137135
return dialogResult;
138136
}
139137

140-
private Document DoImport()
138+
private void DoImport()
141139
{
142140
// set the requested size & resolution for SvgDocument
143141
width = dialog.CanvasW;
@@ -160,7 +158,8 @@ private Document DoImport()
160158
{
161159
using (Bitmap bmp = RenderSvgDocument())
162160
{
163-
return Document.FromImage(bmp);
161+
pdnDocument = Document.FromImage(bmp);
162+
return;
164163
}
165164
}
166165

@@ -184,7 +183,7 @@ private Document DoImport()
184183
if (ShowMemoryWarningDialog(allElements.Count) != DialogResult.Yes)
185184
{
186185
dialog.DialogResult = DialogResult.Cancel;
187-
return null;
186+
return;
188187
}
189188
}
190189

@@ -248,7 +247,7 @@ private Document DoImport()
248247
ShowMemoryWarningDialog(groupsAndElementsWithoutGroup.Count) != DialogResult.Yes)
249248
{
250249
dialog.DialogResult = DialogResult.Cancel;
251-
return null;
250+
return;
252251
}
253252

254253
// Thread safe
@@ -258,21 +257,19 @@ private Document DoImport()
258257
pdnDocument = RenderElements(groupsAndElementsWithoutGroup, setOpacityForLayer, importHiddenLayers,
259258
dialog.ReportProgress, ct);
260259
}
261-
260+
262261
// Fallback. Nothing is added. Render one default layer.
263262
if (pdnDocument == null || pdnDocument.Layers.Count == 0)
264263
{
265264
pdnDocument?.Dispose();
266265
using (Bitmap bmp = RenderSvgDocument())
267266
{
268-
return Document.FromImage(bmp);
267+
pdnDocument = Document.FromImage(bmp);
269268
}
270269
}
271-
272-
return pdnDocument;
273270
}
274271

275-
private Document AfterImport(Task<Document> p)
272+
private void AfterImport(Task p)
276273
{
277274
if (p.Exception != null && !p.IsCanceled)
278275
{
@@ -295,15 +292,13 @@ private Document AfterImport(Task<Document> p)
295292
}
296293

297294
dialog.DialogResult = DialogResult.Cancel;
298-
return null;
295+
return;
299296
}
300297

301298
if (dialog.DialogResult == DialogResult.None)
302299
{
303300
dialog.DialogResult = DialogResult.OK;
304301
}
305-
306-
return p.Result;
307302
}
308303

309304
#region Render Elements

0 commit comments

Comments
 (0)