Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit b8f2f13

Browse files
Catch TaskCancelled exception
1 parent ae8fd5a commit b8f2f13

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

Scripts/Scenes/Main/NetworkManager.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,25 @@ public static async Task WaitForHostToConnectToServer()
130130

131131
public static async Task WaitForClientToConnect(int timeoutMs, CancellationTokenSource cts, Action onClientConnected)
132132
{
133-
cts.CancelAfter(timeoutMs);
134-
await Task.Run(async () =>
133+
try
135134
{
136-
while (!NetworkManager.GameClient.IsConnected)
135+
cts.CancelAfter(timeoutMs);
136+
await Task.Run(async () =>
137137
{
138-
if (cts.IsCancellationRequested)
139-
break;
138+
while (!NetworkManager.GameClient.IsConnected)
139+
{
140+
if (cts.IsCancellationRequested)
141+
break;
140142

141-
await Task.Delay(100);
142-
}
143-
}, cts.Token);
143+
await Task.Delay(100);
144+
}
145+
}, cts.Token);
144146

145-
if (!cts.IsCancellationRequested)
146-
onClientConnected();
147+
if (!cts.IsCancellationRequested)
148+
onClientConnected();
149+
}
150+
catch (Exception)
151+
{ }
147152
}
148153
}
149154

0 commit comments

Comments
 (0)