Click here to Skip to main content
15,907,233 members

Comments by Ramachandran P (Top 3 by date)

Ramachandran P 2-Mar-18 5:34am View    
Thanks again OriginalGriff. I just changed the code like below. But still the same problem occurred.

MainForm.cs:

public partial class MainForm : Form
{

public Form1()
{
InitializeComponent();

InspectorWrapperThread wraperThread = new InspectorWrapperThread();
wraperThread.Start();
}
}


InspectorWrapperThread.cs

public class InspectorWrapperThread : IDisposable
{

BackgroundWorker worker1;

public InspectorWrapperThread()
{

worker1 = new BackgroundWorker();
worker1.WorkerSupportsCancellation = true;
worker1.DoWork += new DoWorkEventHandler(worker1_DoWork);
worker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker1_RunWorkerCompleted);
}

void worker1_DoWork(object sender, DoWorkEventArgs e)
{
Called a function from here.
function1(true);
//Do some work here
}

void worker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// This thread completion getting called correctly.
}

private void function1(bool exe)
{
Wrapper wrapper = new Wrapper();
WorkerThread2 worker = wrapper.Databuff;
object outlookObject = null;
if (Inspector.CurrentItem is MailItem)
{
outlookObject = worker.OutlookMail;

}
else if (Inspector.CurrentItem is AppointmentItem)
{
outlookObject = worker.OutlookAppointment;
}
else if (Inspector.CurrentItem is ContactItem)
{
outlookObject = worker.OutlookContact;
}
CustomTaskPane taskPane = wrapper.CustomTaskPane;

if (taskPane != null)
{
if (taskPane.Visible)
{
var iFrame = taskPane.Control;
if (iFrame != null)
{
UserControlIntelV2 intelControl = (UserControlIntelV2)iFrame;
if (intelControl != null)
{
intelControl.PopulateOutlookListControl();
}
}
}
}
List<string> emailAddresses = new List<string>();
if (outlookObject is ContactItem)
{
var contactEmailAddress = worker.EmailAddressForOutlookContact((ContactItem)outlookObject);
if (!String.IsNullOrEmpty(contactEmailAddress))
{
emailAddresses.Add(contactEmailAddress);
}
}
else
{
emailAddresses = worker.GetSMTPAddressForRecipients(outlookObject);
}
var emailAddress = Utilities.FirstExternalEmail(emailAddresses);
worker.function2();

while (!worker.canCompleteThread)
{
if (worker.canCompleteThread)
{
break;
}
Thread.Sleep(10);
}
}
}

WorkerThread2.cs

public class WorkerThread2 : IDisposable
{
public bool canCompleteThread = false;
private BackgroundWorker backgroundWorkerThread2Tab;

public WorkerThread2()
{
backgroundWorkerThread2Tab = new BackgroundWorker();
backgroundWorkerThread2Tab.WorkerSupportsCancellation = true;
backgroundWorkerThread2Tab.DoWork += new DoWorkEventHandler(backgroundWorkerThread2TabDoWork);
backgroundWorkerThread2Tab.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorkerThread2TabRunWorkerCompleted);
}

public void function2()
{
if (string.IsNullOrWhiteSpace(mail))
return false;

if (!Utilities.InternalOnly(mail))
{
this.email = mail;
this.HitAPIcalls(this.email);
return true;
}

return false;
}

private void HitAPIcalls()
{
// do some operation and call
if (!backgroundWorkerThread2Tab.IsBusy)
backgroundWorkerThread2Tab.RunWorkerAsync(mail);
}

void backgroundWorkerThread2TabDoWork(object sender, DoWorkEventArgs e)
{
//This Dowork event getting called successfully and do all the operation without any issues.
}

void backgroundWorkerThread2TabRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
canCompleteThread = true
// This thread completion never getting called.
}
}
Ramachandran P 2-Mar-18 4:01am View    
Actually, The thread started inside the function HitAPIcalls().


private void function1(bool exe)
{
Wrapper wrapper = new Wrapper();
WorkerThread2 worker = wrapper.Databuff;
object outlookObject = null;
if (Inspector.CurrentItem is MailItem)
{
outlookObject = worker.OutlookMail;

}
else if (Inspector.CurrentItem is AppointmentItem)
{
outlookObject = worker.OutlookAppointment;
}
else if (Inspector.CurrentItem is ContactItem)
{
outlookObject = worker.OutlookContact;
}
CustomTaskPane taskPane = wrapper.CustomTaskPane;

if (taskPane != null)
{
if (taskPane.Visible)
{
var iFrame = taskPane.Control;
if (iFrame != null)
{
UserControlIntelV2 intelControl = (UserControlIntelV2)iFrame;
if (intelControl != null)
{
intelControl.PopulateOutlookListControl();
}
}
}
}
List<string> emailAddresses = new List<string>();
if (outlookObject is ContactItem)
{
var contactEmailAddress = worker.EmailAddressForOutlookContact((ContactItem)outlookObject);
if (!String.IsNullOrEmpty(contactEmailAddress))
{
emailAddresses.Add(contactEmailAddress);
}
}
else
{
emailAddresses = worker.GetSMTPAddressForRecipients(outlookObject);
}
var emailAddress = Utilities.FirstExternalEmail(emailAddresses);
worker.function2();
}

public void function2()
{
if (string.IsNullOrWhiteSpace(mail))
return false;

if (!Utilities.InternalOnly(mail))
{
this.email = mail;
this.HitAPIcalls(this.email);
return true;
}

return false;
}

private void HitAPIcalls(string mail)
{
// From this function, only start the background worker thread alone.
if (!backgroundWorkerThread2Tab.IsBusy)
backgroundWorkerThread2Tab.RunWorkerAsync(mail);
}
Ramachandran P 2-Mar-18 2:59am View    
Hi OriginalGriff,

Thanks for your quick response. For testing purpose, I just return from the DoWork thread. But, in this case too the completion not getting called.

Thank you.