-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto reconnection keeps running after exit play mode in Unity editor #5
Comments
I'm really glad you find the SocketIOUnity repository useful. So for the Editor, I mentioned that i didn't tested, and I noticed that the behavior of the editor varies by unity version number, so don't count on it, check on pc or mobile devices.
// inside SocketManager class
public static SocketManager Instance { get; private set; } = null;
public SocketIOUnity socket;
private void Start()
{
InitInstance();
}
public void InitInstance(bool forceInit = false)
{
if (forceInit || Instance == null)
{
Debug.Log("InitInstance");
Instance = this;
socket = new SocketIOUnity("https://www.example.com");
socket.OnUnityThread("spin", (res) =>
{
// TODO
});
socket.Connect();
DontDestroyOnLoad(transform.root.gameObject);
}
}
public handleSocketReceiving = true;
void OnApplicationFocus(bool paused)
{
handleSocketReceiving = !paused;
}
void OnApplicationPause(bool paused)
{
handleSocketReceiving = !paused;
}
void OnApplicationQuit()
{
handleSocketReceiving = false;
}
// Somewhere
socket.OnUnityThread("spin", (res) =>
{
if(handleSocketReceiving){
//TODO
}
}); I hope these solve the problem. |
Thank you very much for the advice. I will import your code snippets into my code. So background threads can quit properly in a complied executable, right? Is it necessary to manually abort background threads with the code? Thanks again :) |
Greetings! I am having so much fun with SocketIOUnity. Thank you very much for this.
I have run into a problem, where I found the child thread keeps running in the background even though the main thread is exited. I tried to manually call
SocketIOUnity.Disconnect()
inOnApplicationQuit()
andOnDestroy()
to see if I could destroy the child thread, and it failed to do so. I thereby setSocketIOUnity.Options.Reconnection = false
to stop auto-reconnection to the server and it worked (i.e. not attempting to reconnect to the server).However, I am not sure if this can kill all background threads. Am I doing anything wrong? Is there any proper way to exit the main thread with all background threads killed?
Thanks again :)
The text was updated successfully, but these errors were encountered: