Hi, I posted this issue a few weeks ago and the responses helped, I am
still receiving the same error. The error is "An unhandled exception of

type 'System.NullReferenceException'
occurred in system.management.dll
Additional information: Object reference not set to an instance of an
object."

I am creating a multi-winform project. By creating a main form with a
main but when I call another form I create a new thread and exit this
thread


private void lkBuild_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
Application.ExitThread();
Thread td =3D new Thread(new ThreadStart(frmBuild));
td.Start();


}


protected void frmSafetyStock()
{
Application.Run(new frmSafetyStock());


}


Everything has been working fine, except after I perform an update to
the database and decide to Exit the winform after the update operation
is complete. I am using the DAL layer (June 2005 version). To submit
and call the class, the code is below

private void btnSubCdAssign_Click(object sender, System.EventArgs e)
{
try
{
strCheckPoint =3D "Validating the Units and Percentages";
Validate_Units();
Validate_Percentages();


strCheckPoint =3D "Checking for error codes";
if ((Error_Pct + Error_Units) =3D=3D 0)
{
strCheckPoint =3D "Updating the Percentage and Unit Codes";
_codes.Min_1 =3D Convert.ToInt32(ultNumEdMin1.Value);
_codes.Min_2 =3D Convert.ToInt32(ultNumEdMin2.Value);
_codes.Min_3 =3D Convert.ToInt32(ultNumEdMin3.Value);
_codes.Max_2 =3D Convert.ToInt32(lblMax2.Text);
_codes.Max_3 =3D Convert.ToInt32(lblMax3.Text);
_codes.A_Pct =3D Convert.ToSByte(ultNumEdCodeA.Value);
_codes.B_Pct =3D Convert.ToSByte(ultNumEdCodeB.Value);
_codes.UpdateCodes(cbDept.Text, cbItemType.Text);


}


else
{
MessageBox.Show("Please correct the errors highlighted in red.",
"Validation Check", MessageBoxButtons.OK);

}
}


catch (Error err)
{
err.LogError();
MessageBox.Show("Error, please call administrators!" + "\n" + "Error: "

+ err, "Error", MessageBoxButtons.OK ,MessageBoxIcon.Error);
Application.ExitThread();
Thread td =3D new Thread(new ThreadStart(frmMainMenu));
td.Start();
stsFlag =3D true;
this.Close();

}


catch (Exception ex)
{
Error err =3D new Error(ex,
"loadABCandPercentages","frmsafetyStock",ConfigurationSettings.AppSettings[=
=AD"application_name"].ToString(),strCheckPoint,DateTime.Now,

"Mark
Kuhrt",ConfigurationSettings.AppSettings["ErrorTable"].ToString(),Configura=
=ADtionSettings.AppSettings["LogFile"].ToString());

err.LogError();
MessageBox.Show("Error, please call administrators!" + "\n" + "Error: "

+ ex, "Error", MessageBoxButtons.OK ,MessageBoxIcon.Error);
Application.ExitThread();
Thread td =3D new Thread(new ThreadStart(frmMainMenu));
td.Start();
stsFlag =3D true;
this.Close();


}
}


Update Method
public void UpdateCodes(string Department, string ItemType)
{
try
{
strCheckPoint =3D "calling the SP to update the codes for ABC /
Percentage";
Database db =3D
DatabaseFactory.CreateDatabase(ConfigurationSettings.AppSettings["database"=
=AD]);


DBCommandWrapper dbc =3D
db.GetStoredProcCommandWrapper("usp_Inv_UpdateUnitRevenue");
dbc.AddInParameter("@Department", DbType.Int32, Department);
dbc.AddInParameter("@Item_Type", DbType.String, ItemType);
dbc.AddInParameter("@MinCode1", DbType.Int32, _Min_1);
dbc.AddInParameter("@MinCode2", DbType.Int32, _Min_2);
dbc.AddInParameter("@MinCode3", DbType.Int32, _Min_3);
dbc.AddInParameter("@MaxCode2", DbType.Int32, _Max_2);
dbc.AddInParameter("@MaxCode3", DbType.Int32, _Max_3);
dbc.AddInParameter("@A_Pct", DbType.Decimal, _A_Pct);
dbc.AddInParameter("@B_Pct", DbType.Decimal, _B_Pct);
db.ExecuteNonQuery(dbc);


}


catch (SqlException ex)
{
Error err =3D new Error(ex,"Updating the codes","Code
Class",m_ApplicationName,strCheckPoint,DateTime.Now,m_ErrorTable,m_LogFile)=
=AD;

throw (err);

}


catch (Exception ex)
{
Error err =3D new Error(ex,"Updating the codes","Code
Class",m_ApplicationName,strCheckPoint,DateTime.Now,m_ErrorTable,m_LogFile)=
=AD;

throw (err);


}
}


I was initially calling the dispose method but I was told to try the
close() but I still have the same issue.
private void mnuFileExit_Click(object sender, System.EventArgs e)
{
if (stsFlag =3D=3D false)
{
if (MessageBox.Show("Do you want to exit?",
"Exit",MessageBoxButtons.YesNo ) =3D=3D DialogResult.No)
return;


}
this.Close();
}


I am doing something wrong and getting this error corrected will allow
to move this project into end user testing. Any additional advice or
hints is greatly appreciated.