- Home /
Question by
liammfox · Jul 08, 2016 at 08:52 AM ·
networkingthreadsmultithreading
Thread continues to run after game quits
I start a server on a different thread, and things seem to go fine while I'm running my game.
But if I run my game a second time after I exit play mode, Unity freezes.
When I comment out the last line (serverThread.Start()) in the following code, I no longer have this issue.
using System.IO.Pipes;
using System.Threading;
// ...
public static void SomeFunction() {
// ...
serverThread = new Thread(new ThreadStart(() => {
NamedPipeServerStream pipeServer = new NamedPipeServerStream("testpipe",
PipeDirection.InOut, 1, PipeTransmissionMode.Byte);
pipeServer.WaitForConnection();
// ...
// some more stuff that should never be reached
// because client is not yet open
// ...
}));
serverThread.Start();
}
I also tried calling Thread.Abort() on serverThread immediately after starting it (i.e. the next line), but this had no effect.
How can I avoid this situation? Is there a different, safer way to call make a blocking call? Is there a way to abort my thread at some point before exiting that will actually work?
Comment
Your answer
Follow this Question
Related Questions
Multithreaded String Log Doesn't Update 0 Answers
Multi threading problem ! 2 Answers
Unity Threading Issue: Not able to delegate task 0 Answers