I put a lot of information into this problem because I have no idea what relavent will be
Question:
I have a problem with the program that I work on, when they start it, it freezes my entire computer and does not return an error (I am completely unable to do something that CTRL + ALT + DEL does not even work). This program accepts the connection from the android client and the atm Android client is not configured correctly, so the connection is rejected.
Question:
How can I stop my program from freezing my entire machine?
Hypothesis:
I have several theories regarding what is happening, but I donβt know how to fix them. I read that this may have something to do with me when I start a single-threaded process inside my asynchronous worker, but I'm not sure if a socket is a single-threaded process. Also, I'm not quite sure how I should deal with exceptions in backgroundworker, so I just let it go back to RunWorkerCompletedEventArgs and then it gets an error message.
What I tried:
- I tried to set try catch every time, and then delete attempts to catch anything, it seems that I am not able to fix this error
- I checked the system event log and nothing appears, except for my reboots after my computer freezes
- I tried to isolate the problem, but it can happen literally at any time from the program, starting from the moment when I try to connect to
Setup:
I run the program from the professional studio Visual Studio 2012 on a computer with Windows 8 pro. The computer I work on has an i7-3770K 3.50 GHz and 32 GB of RAM. An application trying to establish a connection with mine is an Android application, and the credentials are incorrect when it tries to connect. Visual Studio disconnects my primary hard drive and creates a project on another drive.
Closure:
With all that said, does anyone please agree to help me? If you need more information, I will be happy to provide it, please ask.
The main method:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.ComponentModel; namespace Server {
SSL socket connection:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Net; using System.Net.Sockets; using System.Windows; using System.Windows.Controls; using System.ComponentModel; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using MySql.Data.MySqlClient; using System.IO; namespace Server { public class LoginServer { // Incoming data from the client. public static string data = null; public static X509Certificate serverCertificate = null; public delegate void UpdateListView(ListView oOutput); public void StartListening(BackgroundWorker worker) { // Data buffer for incoming data. byte[] bytes = new Byte[1024]; // Establish the local endpoint for the socket. IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[1]; serverCertificate = X509Certificate.CreateFromCertFile(@"server.crt"); TcpListener oServer = new TcpListener(ipAddress, 12345); // Bind the socket to the local endpoint and // listen for incoming connections. // Start listening for connections. while (true) { Thread.Sleep(100); worker.ReportProgress(0, "Waiting for connection...."); // Program is suspended while waiting for an incoming connection. //Socket handler = listener.Accept(); oServer.Start(); TcpClient oClient = oServer.AcceptTcpClient(); Stream oStream = oClient.GetStream(); SslStream oSSLStream = new SslStream(oStream); data = null; // An incoming connection needs to be processed. string sUsername = "place holder"; string sPassword = "place holder"; while (true) { bytes = new byte[1024]; int bytesRec = oSSLStream.Read(bytes, 0, bytes.Length); data += Encoding.ASCII.GetString(bytes, 0, bytesRec); string[] sCredentials = data.Split("|".ToCharArray()[0]); sUsername = sCredentials[0]; sPassword = sCredentials[1]; if (data.IndexOf("<EOF>") > -1) { break; } } // Show the data on the console. worker.ReportProgress(0, "Connection Recieved : "); worker.ReportProgress(0, "Username: " + sUsername); worker.ReportProgress(0, "Password: " + sPassword); worker.ReportProgress(0, ""); // Echo the data back to the client. byte[] msg; if (sUsername.Equals("test") && sPassword.Equals("test")) { msg = Encoding.ASCII.GetBytes("approved<EOF>\n"); worker.ReportProgress(0, "approved"); oSSLStream.Write(msg, 0, msg.Length); } else { msg = Encoding.ASCII.GetBytes("rejected<EOF>\n"); worker.ReportProgress(0, "rejected"); oSSLStream.Write(msg, 0, msg.Length); } } } public void VerifyUser() { } } }