Hi
I am trying to get access to form controls from a separate thread to that of the application. After some hunting I found this article: which has helped
As I have a number of controls that I need to reference and control I thought I would create a property for each control and reference that.
This is what I devised:
If I use the get accessor I get a null reference exception
(I have not yet tried the set).
A bit of background:
+ This is being developed using the Compact Framework 2.0 (hence the declaration of MethodInvoker).
+ The calling thread is being created using the OpenNETCF LargeIntervalTimer object.
Any ideas?? What am I doing wrong? I'm a bit of a novice when it comes to threading techniques...
Cheers
Rob
I am trying to get access to form controls from a separate thread to that of the application. After some hunting I found this article: which has helped
As I have a number of controls that I need to reference and control I thought I would create a property for each control and reference that.
This is what I devised:
Code:
public delegate void MethodInvoker();
public TextBox _txtLink
{
get
{
if (this.txtLink.InvokeRequired)
{
TextBox txt = null;
this.txtLink.BeginInvoke(
new MethodInvoker(
delegate() { txt = this.txtLink; }));
try
{
MessageBox.Show(txt.Text);
}
catch (Exception ex)
{
MessageBox.Show("oops - " + ex.Message);
}
return txt;
}
else
{
return this.txtLink;
}
}
set
{
if (this.txtLink.InvokeRequired)
{
this.txtLink.BeginInvoke(
new MethodInvoker(
delegate() { _txtLink = value; }));
}
else
{
this.txtLink = value;
}
}
}
If I use the get accessor I get a null reference exception
A bit of background:
+ This is being developed using the Compact Framework 2.0 (hence the declaration of MethodInvoker).
+ The calling thread is being created using the OpenNETCF LargeIntervalTimer object.
Any ideas?? What am I doing wrong? I'm a bit of a novice when it comes to threading techniques...
Cheers
Rob