Code:
public partial class Form1 : Form
{
public ts_connection conn = new ts_connection();
public Connection handler;
private void Button1_Click(object sender, EventArgs e)
{
try
{
handler = conn.make_connection();
handler.Stop(); // <== This triggers the error.
try
{
this.Close();
Thread thread1 = new Thread(start1);
thread1.SetApartmentState(ApartmentState.MTA);
thread1.Start();
}
catch (Exception er22)
{
MessageBox.Show("Connecting to Server failed.\n Exception: " + er22.ToString(), "NTSMS - Connection failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}catch(Exception err3)
{
MessageBox.Show("Connecting to Server failed.\n Exception: " + err3.ToString(), "NTSMS - Connection failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
void start1()
{
Application.Run(new MainForm(handler));
}
}
}
public class ts_connection
{
static byte[] WaveHeader = new byte[]
{
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20,
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x80, 0xBB, 0x00, 0x00, 0x00, 0xB8, 0x0B, 0x00,
0x10, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
};
static FileStream WaveFile;
public Connection make_connection(string identity = null, string server_ip = "localhost", uint server_port = 9987, string client_name = "test_client", string server_password = "secret")
{
using (Connection connection = Library.SpawnNewConnection())
{
try
{
connection.StatusChanged += Connection_StatusChanged;
connection.NewChannel += Connection_NewChannel;
connection.NewChannelCreated += Connection_NewChannelCreated;
connection.ChannelDeleted += Connection_ChannelDeleted;
connection.ClientMoved += Connection_ClientMoved;
connection.ClientMovedSubscription += Connection_SubscriptionClientMoved;
connection.ClientTimeout += Connection_ClientTimeout;
connection.TalkStatusChanged += Connection_TalkStatusChanged;
connection.WhisperIgnored += Connection_WhisperIgnored;
connection.ServerError += Connection_ServerError;
connection.EditMixedPlaybackVoiceData += Connection_EditMixedPlaybackVoiceData;
if (identity == null)
{
identity = Library.CreateIdentity();
}
Task task = connection.Start(identity, server_ip, server_port, client_name, serverPassword: server_password);
task.Wait();
//MessageBox.Show("Connection established!", "NTSMS - Connection Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
return connection;
}
catch (AggregateException err)
{
if (err.InnerException is TeamSpeakException)
{
Error errorCode = ((TeamSpeakException)err.InnerException).ErrorCode;
// MessageBox.Show(errorCode.ToString(), "Error Exception thrown", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
else
{
throw;
}
}
}
}
[... just some functions, that are not used yet ...]
}