15,907,233 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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.