problem accessing a control from a thread (the callback is in another user defined class)
-
Hi, I have a custom class CReadCDD where I intend to do some processing. I placed the callbacks also inside this class (like mLoadXmlOnHeap_WorkThread). From the Form class I instantiate my CReadCDD class and create the thread with call to mLoadXmlOnHeap_WorkThread. In mLoadXmlOnHeap_WorkThread (not to have an additional proprty for the Form, I send an event to the Form class with the text I want as event args); the event is received in the Forms class, it goes to mfHandleCustomEvent_PrintRichTextConsole but here after entering in Invoke method IT BLOCK my Form. The richtext control is not updated. Where I did the mistake? I read the MSDN but still I have problem to access the control from my thread :) George
public class CReadCDD { //Fields private CProcessXMLdoc mdoc; private string mFileName; public RichTextBox pRichTextBox1 {get; set;} //private Form1 myForm; // Declare the event using EventHandler<T> public event EventHandler<CCustomEventArgs> RaiseCustomEvent; protected void pOnRaiseCustomEvent(CCustomEventArgs pEv) { EventHandler<CCustomEventArgs> handler = RaiseCustomEvent; // Event will be null if there are no subscribers if (handler != null) handler(this, pEv); } public CReadCDD(string pFileName, Form1 pForm) { //mDelSetText= mSetText; mFileName= pFileName; //myForm= pForm; } #region Worker Threads public void mLoadXmlOnHeap\_WorkThread() { mdoc = new CProcessXMLdoc(mFileName); CCustomEventArgs evObj= new CCustomEventArgs("Load The XML Data from Cdd file on the HEAP\\n"); pOnRaiseCustomEvent(evObj); } // ...................................... }
namespace CddToCaplDiagnosticTestsGenerator
{
public partial class Form1 : Form
{private CReadCDD objReadCdd; public delegate void DelegateTypePrntText(string text); public DelegateTypePrntText mdelT; public Form1() { mdelT = new DelegateTypePrntText(mSetTextToRichTextControl); InitializeComponent(); } // Define what actions to take when the event is raised. void mfHandleCustomEvent\_PrintRichTextConsole(object sender, CCustomEventArgs e) { byte debug=0; string
-
Hi, I have a custom class CReadCDD where I intend to do some processing. I placed the callbacks also inside this class (like mLoadXmlOnHeap_WorkThread). From the Form class I instantiate my CReadCDD class and create the thread with call to mLoadXmlOnHeap_WorkThread. In mLoadXmlOnHeap_WorkThread (not to have an additional proprty for the Form, I send an event to the Form class with the text I want as event args); the event is received in the Forms class, it goes to mfHandleCustomEvent_PrintRichTextConsole but here after entering in Invoke method IT BLOCK my Form. The richtext control is not updated. Where I did the mistake? I read the MSDN but still I have problem to access the control from my thread :) George
public class CReadCDD { //Fields private CProcessXMLdoc mdoc; private string mFileName; public RichTextBox pRichTextBox1 {get; set;} //private Form1 myForm; // Declare the event using EventHandler<T> public event EventHandler<CCustomEventArgs> RaiseCustomEvent; protected void pOnRaiseCustomEvent(CCustomEventArgs pEv) { EventHandler<CCustomEventArgs> handler = RaiseCustomEvent; // Event will be null if there are no subscribers if (handler != null) handler(this, pEv); } public CReadCDD(string pFileName, Form1 pForm) { //mDelSetText= mSetText; mFileName= pFileName; //myForm= pForm; } #region Worker Threads public void mLoadXmlOnHeap\_WorkThread() { mdoc = new CProcessXMLdoc(mFileName); CCustomEventArgs evObj= new CCustomEventArgs("Load The XML Data from Cdd file on the HEAP\\n"); pOnRaiseCustomEvent(evObj); } // ...................................... }
namespace CddToCaplDiagnosticTestsGenerator
{
public partial class Form1 : Form
{private CReadCDD objReadCdd; public delegate void DelegateTypePrntText(string text); public DelegateTypePrntText mdelT; public Form1() { mdelT = new DelegateTypePrntText(mSetTextToRichTextControl); InitializeComponent(); } // Define what actions to take when the event is raised. void mfHandleCustomEvent\_PrintRichTextConsole(object sender, CCustomEventArgs e) { byte debug=0; string
After the first look I would say
thrdLoadXmlOnHeap.Join();
is your problem. After you started your thread from your main/guithread your main/guithread waits for the end of the thread you started. This blocks your ui. At first I would try just to comment this line out.Greetings Covean
-
After the first look I would say
thrdLoadXmlOnHeap.Join();
is your problem. After you started your thread from your main/guithread your main/guithread waits for the end of the thread you started. This blocks your ui. At first I would try just to comment this line out.Greetings Covean
Yep... thx
-
Yep... thx