Skip to content

Commit 2c52d84

Browse files
committed
Was made refactoring
1 parent 0d3274a commit 2c52d84

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/JavaScriptEngineSwitcher.ChakraCore/ScriptDispatcher.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private void StartThread()
102102
task = _taskQueue.Dequeue();
103103
if (task == null)
104104
{
105+
_taskQueue.Clear();
105106
return;
106107
}
107108
}
@@ -177,6 +178,11 @@ public T Invoke<T>(Func<T> func)
177178
{
178179
VerifyNotDisposed();
179180

181+
if (func == null)
182+
{
183+
throw new ArgumentNullException("func");
184+
}
185+
180186
return (T)InnnerInvoke(() => func());
181187
}
182188

@@ -189,6 +195,11 @@ public void Invoke(Action action)
189195
{
190196
VerifyNotDisposed();
191197

198+
if (action == null)
199+
{
200+
throw new ArgumentNullException("action");
201+
}
202+
192203
InnnerInvoke(() =>
193204
{
194205
action();
@@ -217,25 +228,17 @@ private void Dispose(bool disposing)
217228
if (_disposedFlag.Set())
218229
{
219230
EnqueueTask(null);
220-
_thread.Join();
221231

222-
if (_waitHandle != null)
232+
if (_thread != null)
223233
{
224-
_waitHandle.Dispose();
225-
_waitHandle = null;
234+
_thread.Join();
235+
_thread = null;
226236
}
227237

228-
if (disposing)
238+
if (_waitHandle != null)
229239
{
230-
lock (_taskQueueSynchronizer)
231-
{
232-
if (_taskQueue != null)
233-
{
234-
_taskQueue.Clear();
235-
}
236-
}
237-
238-
_thread = null;
240+
_waitHandle.Dispose();
241+
_waitHandle = null;
239242
}
240243
}
241244
}

0 commit comments

Comments
 (0)