i am using threading method in generating the sql command
to prevent my main application getting freeze
but when i try to add a new panel after sucessfully connected with the server
but i triggered an error :
cross-thread operation not valid..
i read several article from google a lot of people said that it is not a best way to add any user control with using threading
so i tried another method
1st abort my thread as u can see at openConnection, LoadConnection.Abort(); is commend.
after i abort it i tried this method
if (loadConnection.IsAlive) { }
else{
if (connectionStatus == "connectionSucceed") { }
else if (connectionStatus == "connectionFail") {
var panel = new Panel(){ new size(100,100), location (0,0);}
}
}
but this time nothing happen.
is there any way to add any user control to the main form while running the sql command without freezing the UI??
What I have tried:
using System.Threading;
using MySql.Data.MySqlClient;
namespace databaseCommand{
public static class mainCommand {
private static Thread loadConnection = new Thread(new ThreadStart(openConnection));
private static MySqlConnection con;
private static string connectionStatus;
public static void startConnection() {
loadConnection.Start();
}
private static void openConnection() {
con = new MySqlConnection("server=localhost;user=root;database=bookbardatabase;port=3306;password=");
try{
con.Open();
}
catch (Exception ex){
var panel = new Panel(){ new size(100,100), location (0,0);}
}
}
}
}