BackgroundWorker Does Not Fire RunWorkerCompleted

  • Thread starter Thread starter VAADADMIN
  • Start date Start date
V

VAADADMIN

I have a small app that I am working with to create LDIF files from
text files. I have a pictureBox that has an animated GIF that will
appear on the form when the LDIF are being created. The pictureBox
appears and the GIF is there, but it does not stop when called. So
when I debug, the RunWorkerCompleted event never fires. Is there
anything in my code that is obvious as to why.

Code:
private void createLDIF_btn_Click(object sender, EventArgs e)
{
ldifCreate_lbl.Visible = false;
string saveFolder2;
if (addMembers_chk.Checked == false &&
addGroup_chk.Checked == false)
{
MessageBox.Show("Please Check At Least One Option");
return;
}
if (folderBrowserDialog2.ShowDialog() == DialogResult.OK)
{
if ((saveFolder2 = folderBrowserDialog2.SelectedPath) !
= null)
{
pictureBox1.Visible = true;
backgroundWorker1.RunWorkerAsync(saveFolder2);
}
}
}

private void createLDIFs(string saveFolder2)
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
string sLine1;

using (StreamReader sr1 = new
StreamReader(listBox1.Items[i].ToString()))
{
StreamWriter addgroupLDF =
File.AppendText(saveFolder2.ToString() + "\\RACF_ADDGROUP_LDF.ldf"); //
enter the full path for the output file
StreamWriter connectLDF =
File.AppendText(saveFolder2.ToString() + "\\RACF_CONNECT_LDF.ldf"); //
enter the full path for the output file
StreamWriter addsdLDF =
File.AppendText(saveFolder2.ToString() + "\\RACF_ADDSD_LDF.ldf"); //
enter the full path for the output file

while ((sLine1 = sr1.ReadLine()) != null)
{
string owner = @"(.\b(owner)\b\W.*?\W)";
string data = @"(.\b(data)\b\W\W.*?\W\W)";
string superGroup = @"(.\b(supgroup)\b\W.*?
\W)";
string groupReg = @"(.\b(group)\b\W.*\s.*?
\W)";

Match ownerMatch = Regex.Match(sLine1, owner);
Match dataMatch = Regex.Match(sLine1, data);
Match superGroupMatch = Regex.Match(sLine1,
superGroup);
Match groupMatch = Regex.Match(sLine1,
groupReg);

string owner1 = ownerMatch.Value.ToString();
string dataStr =
StringHelpers.Between(dataMatch.Value.ToString(), '\'', '\'');
string supGroupStr =
superGroupMatch.Value.ToString();
string groupStr =
StringHelpers.Between(groupMatch.Value.ToString(), '(', ')').Replace("
", "");
string grpName = StringHelpers.Between(sLine1,
' ', ' ');

if (addGroup_chk.Checked)
{
if (sLine1.StartsWith("addgroup"))
{

if (grpName.Contains("#"))
{
addgroupLDF.WriteLine("dn: cn=\\"
+ grpName + ",cn=Enterprise Server User Groups,cn=micro
focus,cn=program data,dc=test,dc=com");
}
else
{
addgroupLDF.WriteLine("dn: cn=" +
grpName + ",cn=Enterprise Server User Groups,cn=micro focus,cn=program
data,dc=test,dc=com");
}
addgroupLDF.WriteLine("changetype:
add");

addgroupLDF.WriteLine("adminDisplayName: " + grpName);
addgroupLDF.WriteLine("objectClass:
microfocus-MFDS-Group");
addgroupLDF.WriteLine("microfocus-MFDS-
UID: " + grpName);
if (dataStr != "")
{

addgroupLDF.WriteLine("description: " + dataStr);
}
addgroupLDF.WriteLine();
}
}

if (addMembers_chk.Checked)
{
if (sLine1.StartsWith("connect"))
{
string userName =
StringHelpers.Between(sLine1, ' ', ' ');
if (groupStr.Contains("#"))
{
connectLDF.WriteLine("dn: cn=\\" +
groupStr + ",cn=Enterprise Server User Groups,cn=micro
focus,cn=program data,dc=test,dc=com");
}
else
{
connectLDF.WriteLine("dn: cn=" +
groupStr + ",cn=Enterprise Server User Groups,cn=micro
focus,cn=program data,dc=test,dc=com");
}
connectLDF.WriteLine("changetype:
modify");
connectLDF.WriteLine("add: microfocus-
MFDS-Group-Member");
connectLDF.WriteLine("microfocus-MFDS-
Group-Member: " + userName);
connectLDF.WriteLine("-");
connectLDF.WriteLine();
}
}

if (sLine1.StartsWith("addsd"))
{
string resourceName =
StringHelpers.Between(sLine1, '\'', '\'');
addsdLDF.WriteLine("dn: cn=" +
resourceName + ",cn=Enterprise Server Resources,cn=micro
focus,cn=program data,dc=test,dc=com");
addsdLDF.WriteLine("changetype: add");
addsdLDF.WriteLine("objectClass:
microfocus-MFDS-Resource");
addsdLDF.WriteLine("microfocus-MFDS-
Resource-Class: ");
addsdLDF.WriteLine();
}
}
sr1.Close();
addgroupLDF.Close();
connectLDF.Close();
addsdLDF.Close();
}
}
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs
e)
{
createLDIFs(e.Argument.ToString());
}

private void backgroundWorker1_RunWorkerCompleted(object
sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
MessageBox.Show("Error");
}
else if (e.Cancelled)
{
MessageBox.Show("CANCELLED. ");
}
else
{
MessageBox.Show("Finished");
MessageBox.Show(e.Result.ToString());
}
}
 
I have a small app that I am working with to create LDIF files from
text files. I have a pictureBox that has an animated GIF that will
appear on the form when the LDIF are being created. The pictureBox
appears and the GIF is there, but it does not stop when called. So
when I debug, the RunWorkerCompleted event never fires. Is there
anything in my code that is obvious as to why.

First, since you don't show the designer code, just check to make sure
the event is still hooked up (g)

Second, it looks like you are accessing the gui components from the
background worker thread. That's bad, and can cause all sorts of
problems
 
Back
Top