Skip to content

Commit 8aa7f18

Browse files
committed
Fixed Unity Editor freezing when restarting data recording scene
1 parent f25c702 commit 8aa7f18

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Assets/Scripts/BackgroundDataProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public abstract class BackgroundDataProvider : IDisposable
1010
public bool IsRunning { get; set; } = false;
1111
private CancellationTokenSource _cancellationTokenSource;
1212
private CancellationToken _token;
13+
private Task _backgroundThread;
1314

1415
public BackgroundDataProvider(int id)
1516
{
@@ -18,7 +19,7 @@ public BackgroundDataProvider(int id)
1819
#endif
1920
_cancellationTokenSource = new CancellationTokenSource();
2021
_token = _cancellationTokenSource.Token;
21-
Task.Run(() => RunBackgroundThreadAsync(id, _token));
22+
_backgroundThread = Task.Run(() => RunBackgroundThreadAsync(id, _token));
2223
}
2324

2425
private void OnEditorClose()
@@ -58,6 +59,7 @@ public void Dispose()
5859
UnityEditor.EditorApplication.quitting -= OnEditorClose;
5960
#endif
6061
_cancellationTokenSource?.Cancel();
62+
_backgroundThread.Wait();
6163
_cancellationTokenSource?.Dispose();
6264
_cancellationTokenSource = null;
6365
}

0 commit comments

Comments
 (0)