Reading access component from other thread.(thread stopped excepti

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some unreasonable issue while reading access component from other
thread.
I have a Form class which includes TreeView, this tree view includes some
TreeNodes , lets say 2 .
In my Form class I define an arraylist which include reference to those
TreeNodes.

ArayList myTNodesPackage (define ...)
myTNodesPackage.Add….

Now I have:
myTNodesPackage[0] = treeNode1
myTNodesPackage[2] = treeNode2
I create tread and start it as following:
// ExecuteThread thread Class
m_ExecuteThread = new ExecuteThread(this);
this.ExecuteCommandsThread = new Thread(new
ThreadStart(m_ExecuteThread.Go_Execution_AllTests));
this.ExecuteCommandsThread.Start();

In my thread Go_Execution_AllTests function start running and do something
until the following line code:

rootNode = (TreeNode)this.myForm.myTNodesPackage [0];
Now I can see that this access cause somtiong since my debug start respond
sloly.I see that rootNode.Text is OK but all other properties are not
available "error : cannot obtain value".

If I continue debugging the following code I will get an exception "Thread
was being stoped." .
if(rootNode.Checked==false)

Any one can explain me why ? and what should I do ?
Why thread stopped ?
 
I have some unreasonable issue while reading access component
from other thread.
I have a Form class which includes TreeView, this tree view
includes some TreeNodes , lets say 2 .
In my Form class I define an arraylist which include reference
to those TreeNodes.

ArayList myTNodesPackage (define ...)
myTNodesPackage.Add….

Now I have:
myTNodesPackage[0] = treeNode1
myTNodesPackage[2] = treeNode2
I create tread and start it as following:
// ExecuteThread thread Class
m_ExecuteThread = new ExecuteThread(this);
this.ExecuteCommandsThread = new Thread(new
ThreadStart(m_ExecuteThread.Go_Execution_AllTests));
this.ExecuteCommandsThread.Start();

In my thread Go_Execution_AllTests function start running and do
something until the following line code:

rootNode = (TreeNode)this.myForm.myTNodesPackage [0];
Now I can see that this access cause somtiong since my debug
start respond sloly.I see that rootNode.Text is OK but all other
properties are not available "error : cannot obtain value".

If I continue debugging the following code I will get an
exception "Thread was being stoped." .
if(rootNode.Checked==false)

Any one can explain me why ? and what should I do ?
Why thread stopped ?

Yosi,

Only the form's thread, or a thread it starts thru Invoke or BeginInvoke,
can modify a visual control.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
 
I know that read access is avialable from another threades but write is not
accessable.
And also I know that this in framewark 2 not 1.1.
thanks for helping.

Chris R. Timmons said:
I have some unreasonable issue while reading access component
from other thread.
I have a Form class which includes TreeView, this tree view
includes some TreeNodes , lets say 2 .
In my Form class I define an arraylist which include reference
to those TreeNodes.

ArayList myTNodesPackage (define ...)
myTNodesPackage.Add….

Now I have:
myTNodesPackage[0] = treeNode1
myTNodesPackage[2] = treeNode2
I create tread and start it as following:
// ExecuteThread thread Class
m_ExecuteThread = new ExecuteThread(this);
this.ExecuteCommandsThread = new Thread(new
ThreadStart(m_ExecuteThread.Go_Execution_AllTests));
this.ExecuteCommandsThread.Start();

In my thread Go_Execution_AllTests function start running and do
something until the following line code:

rootNode = (TreeNode)this.myForm.myTNodesPackage [0];
Now I can see that this access cause somtiong since my debug
start respond sloly.I see that rootNode.Text is OK but all other
properties are not available "error : cannot obtain value".

If I continue debugging the following code I will get an
exception "Thread was being stoped." .
if(rootNode.Checked==false)

Any one can explain me why ? and what should I do ?
Why thread stopped ?

Yosi,

Only the form's thread, or a thread it starts thru Invoke or BeginInvoke,
can modify a visual control.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
 
NO, you should not "access" UI elements (except menu's) from another thread
than the thread that created the UI elements.
And here "access" means reading and writing! And it doesn't matter wheter
you are using 1.1 or 2.0 it's not due to .NET it's imposed by Windows
itself.


Willy.

I know that read access is avialable from another threades but write is not
accessable.
And also I know that this in framewark 2 not 1.1.
thanks for helping.

Chris R. Timmons said:
I have some unreasonable issue while reading access component
from other thread.
I have a Form class which includes TreeView, this tree view
includes some TreeNodes , lets say 2 .
In my Form class I define an arraylist which include reference
to those TreeNodes.

ArayList myTNodesPackage (define ...)
myTNodesPackage.Add….

Now I have:
myTNodesPackage[0] = treeNode1
myTNodesPackage[2] = treeNode2
I create tread and start it as following:
// ExecuteThread thread Class
m_ExecuteThread = new ExecuteThread(this);
this.ExecuteCommandsThread = new Thread(new
ThreadStart(m_ExecuteThread.Go_Execution_AllTests));
this.ExecuteCommandsThread.Start();

In my thread Go_Execution_AllTests function start running and do
something until the following line code:

rootNode = (TreeNode)this.myForm.myTNodesPackage [0];
Now I can see that this access cause somtiong since my debug
start respond sloly.I see that rootNode.Text is OK but all other
properties are not available "error : cannot obtain value".

If I continue debugging the following code I will get an
exception "Thread was being stoped." .
if(rootNode.Checked==false)

Any one can explain me why ? and what should I do ?
Why thread stopped ?

Yosi,

Only the form's thread, or a thread it starts thru Invoke or BeginInvoke,
can modify a visual control.


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
 
Back
Top