internal void Stop() { lock (this) { Worker.Abort(); } }
public void Quit() { lock (this) { if (Worker != null) { Worker.Interrupt(); Worker.Abort(); Worker = null; } } }
static void Main() {// The thread is aborted in the start method. Worker w = new Worker(); Thread t = new Thread(w.Work); t.Start(); Thread.Sleep(1000); // Main thread sleeps for 1000 ms Console.WriteLine("Aborting "); w.Abort(); Console.WriteLine("Aborted "); }
private void UpdateClient() { while (Client.DataAvailable) { var packet = ClientStream.ReadPacket(Craft.Net.PacketDirection.Serverbound); Log.LogPacket(packet, true); if (packet is EncryptionKeyResponsePacket) { if (!FinializeClientEncryption((EncryptionKeyResponsePacket)packet)) { if (ConnectionClosed != null) { ConnectionClosed(this, null); } Worker.Abort(); return; } } else { var eventArgs = new IncomingPacketEventArgs(packet, true); if (IncomingPacket != null) { IncomingPacket(this, eventArgs); } lock (Server) { if (!eventArgs.Handled) { ServerStream.WritePacket(packet, Craft.Net.PacketDirection.Serverbound); } // We use a BufferedStream to make sure packets get sent in one piece, rather than // a field at a time. Flushing it here sends the assembled packet. Server.Flush(); } if (packet is DisconnectPacket) { Console.WriteLine("Client disconnected: " + ((DisconnectPacket)packet).Reason); if (ConnectionClosed != null) { ConnectionClosed(this, null); } Worker.Abort(); } } } }
private void UpdateServer() { while (Server.DataAvailable) { var packet = ServerStream.ReadPacket(Craft.Net.PacketDirection.Clientbound); Log.LogPacket(packet, false); if (packet is EncryptionKeyRequestPacket) { InitializeEncryption((EncryptionKeyRequestPacket)packet); } else { var eventArgs = new IncomingPacketEventArgs(packet, false); if (IncomingPacket != null) { IncomingPacket(this, eventArgs); } lock (Client) { if (!eventArgs.Handled) { ClientStream.WritePacket(packet, Craft.Net.PacketDirection.Clientbound); } Client.Flush(); } if (packet is DisconnectPacket) { Console.WriteLine("Server disconnected: " + ((DisconnectPacket)packet).Reason); if (ConnectionClosed != null) { ConnectionClosed(this, null); } Worker.Abort(); } } } }
public void StopBuild() { if (Worker != null) { Worker.Abort(); Worker = null; if (buildHelper != null) { buildHelper.AbortProcess(); buildHelper = null; } foreach (var proj in projBuilds) { if (proj.Status == Project.BuildStatus.Progress) { proj.Status = Project.BuildStatus.Wait; } } OnBuildComplete(null); } }
public void Stop() { Worker.Abort(); }
public virtual void Abort() { Worker.Abort(); RunOnCanceled(); }