I am using thread because when open a form the fill the background data in combobox and store procedure combobox data successfully but issue is when I open a form and immediately I press the close button then give an
error like:
internal connection fatal error
connection close
I am trying but not able to solve this error
please help
myform.cs
- public void ShowForm()
- {
- this.Show(); //here open a form
- WorkerSetControl(() => Load_Datas()); //call a thread
- }
Thread ObjThreads;
- private void WorkerSetControl(Action methodName)
- {
- ObjThreads = new Thread(new ThreadStart(() => methodName()));
- //ObjThread.IsBackground = true;
- //ObjThread.SetApartmentState(ApartmentState.STA);
- ObjThreads.Start();
- //if (!ObjThread.Join(TimeSpan.FromSeconds(30)))
- //{
- // ObjThread.Abort();
- // throw new Exception("More than 30 secs.");
- //}
- }
- public void Load_Datas()
- {
- _product.FillForCombo(_prdcode, _prdtype, UltCmbprdType.Text);
- _product.SetColumn(_PrdMast.TableNameProductList, "CODE,DESC,RG", "90,100,200");
- _product._SetDataBinding(_ProdDS, TableNameProductList, true);
- }
- protected override void OnFormClosing(FormClosingEventArgs e) //Here I am closing a form
- {
- this.Enabled = false; // or this.Hide()
- //ObjThreads.IsBackground = false;
- //Thread.Sleep(1);
- //_product.ds = null;
- this.Hide();
- }
_Prod.cs
- public DataSet DS
- {
- get { return _DS; }
- set { _DS = value; }
- }
- public void FillForCombo(string pStrCompCode, string pMast_Type, string pStsOrdType = "")
- {
- Ope.Clear();
- Ope.AddParams("Cmp_Code", pStrCompCode);
- Ope.AddParams("M_Type", pMast_Type);
- Ope.AddParams("P_TYPE", pStsOrdType);
- //if(ConnectionState.Open != ConnectionState.Closed)
- //{
- //if (Ope.IsConnectionCheck(Ope.EnumServer.servername) == true)
- //Ope.OpenConnection(Ope.EnumServer.servername);
- Ope.FillDataSet(Ope.EnumServer.servername, DS, TableNameProductList, Spp.usp_PrdsFillForCombo, Ope.GetParams());
- //here give an error internal connection fatal error / connection closed error when open a form and immidiately i close a form then give an error
- }
OperationSql
- namespace DataLib
- {
- public class OperationSql : GlobalSql
- {
- public static CultureInfo CultureInfoUS;
- public static Hashtable HTParam;
- public static int IntParamCount;
- public OperationSql();
- public static void CCon(EnumServer ServerCon);
- public static void CCon(SqlConnection pConn);
- public static void Clear();
- public static void CloseConnection(EnumServer ServerCon);
- public static void ClsRed(SqlDataReader pReader);
- public static bool OpenConnection(EnumServer ServerCon);
- public static void FillDataSet(EnumServer ServerConn, DataSet pDataSet, string pTableName, string pProcedureName, SqlParameter[] pParamList, bool pSetTime = false, bool pBlnCatch = true);
- public enum EnumServer
- {
- servername = 1,
- servernamesd = 2
- }
- }
when i open a form and after sometime I press close button then not give an error but when I open a form and suddenly press a button then give an error
internal connection fatal error / connection close error / object referance not set to an object
I know why give an error because thread running in background and I press the close button quickly when open a form that is problem
please help
R.D IpPosted Apr 28, 2021, 5:15 AM
Amit GuptaPosted Apr 27, 2021, 11:19 AM
R.D IpPosted Apr 27, 2021, 11:13 AM
Amit GuptaPosted Apr 27, 2021, 11:05 AM
R.D IpPosted Apr 27, 2021, 10:54 AM
Amit GuptaPosted Apr 27, 2021, 10:47 AM
R.D IpPosted Apr 27, 2021, 10:42 AM
Amit GuptaPosted Apr 27, 2021, 10:25 AM