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();
- WorkerSetControl(() => Load_Datas());
- }
Thread ObjThreads;
- private void WorkerSetControl(Action methodName)
- {
- ObjThreads = new Thread(new ThreadStart(() => methodName()));
-
-
- ObjThreads.Start();
-
-
-
-
-
-
- }
-
- 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)
- {
- this.Enabled = false;
-
-
-
- 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);
-
-
-
-
-
- Ope.FillDataSet(Ope.EnumServer.servername, DS, TableNameProductList, Spp.usp_PrdsFillForCombo, Ope.GetParams());
-
- }
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