Sorry to post one issue here which is related to code. i was debugging a code which was wrote long time back by one developer. the issue is two function is called parallel using thread and one function set a variable true at end and another function just looping until the variable is set to true. the variable value is not getting set to true. here i am posting a code snippet and just tell me what is mistake in the code for which variable is not getting set to true by first function.
when user click button then two function is invoked
private void UPDATE_Click(object sender, System.EventArgs e)
{
SavedFirst();
AddCheckThread();
}
public void SavedFirst()
{
IsOpen = true;
System.Threading.Thread loadT = new System.Threading.Thread(new System.Threading.ThreadStart(SaveAll));
loadT.Start();
IsOpen = false;
}
private void AddCheckThread()
{
if (!ALLFlag)
{
loadingThread = new System.Threading.Thread(new System.Threading.ThreadStart(addCheck));
loadingThread.Priority = System.Threading.ThreadPriority.Lowest;
loadingThread.Start();
}
}
private void SaveAll()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate
{
ALLFlag = false;
if (!ALLFlag)
{
loadingThread = new System.Threading.Thread(new System.Threading.ThreadStart(AddProducts));
loadingThread.Priority = System.Threading.ThreadPriority.Lowest;
loadingThread.Start();
}
}));
return;
}
}
private void AddProducts()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate
{
ALLFlag = false;
if (System.Windows.Forms.MessageBox.Show(this, "Would you like to add the details into the Database?", "Add?", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
if (comboOUR.SelectedItem == null || comboCountry.SelectedItem == null || comboSelleble.SelectedItem == null || txtOereff.Text == "" || txtUKPrice.Text == "" || txtUSPrice.Text == "" || txtSUrCharge.Text == "" || txtOURUS.Text == "" || txtOURUK.Text == "")
{
FormValidation();
}
else
{
Gather_Data();
bool isInserted = false;
if (System.Windows.Forms.MessageBox.Show(this, "Would you like to add the details into \"Detailed-Product\" Too?", "Add?", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
isInserted = bbaProduct.BBASaveProduct();
if (isInserted == true)
{
isInserted = false;
isInserted = bbaProduct.InsertInProductTable(BBAProduct.DetailProductID);
if (isInserted == true)
{
System.Windows.Forms.MessageBox.Show(this, "Product Successfully Added ", "Add");
}
else
{
System.Windows.Forms.MessageBox.Show(this, "Error Occurred !! Not Added Into the Database ", "Add");
}
}
else
{
System.Windows.Forms.MessageBox.Show(this, "Error Occurred !! Not Added Into the Database ", "Add");
}
}
else
{
isInserted = bbaProduct.InsertInProductTable(0);
if (isInserted == true)
{
System.Windows.Forms.MessageBox.Show(this, "Successfully Inserted Into the database", "Add");
}
else
{
System.Windows.Forms.MessageBox.Show(this, "Error Occurred !! Not Added Into the Database", "Add");
}
}
}
}
else
{
System.Windows.Forms.MessageBox.Show(this, "Process Cancelled By The User", "Add");
}
ALLFlag = true;
}));
return;
}
}
#region Add Check
private void addCheck()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate
{
this.Opacity = 0.8;
axShockwaveFlash1.Visible = true;
axShockwaveFlash1.Play();
while (!ALLFlag)
{
int x = 0;
}
axShockwaveFlash1.Visible = false;
axShockwaveFlash1.Visible = false;
axShockwaveFlash1.StopPlay();
this.Opacity = 1;
ALLFlag = false;
loadingThread.Abort();
}));
return;
}
}
help me to locate where is the mistake for which ALLFlag
value is not getting set to true. thanks