473,624 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Treeview and Delegate stuff...

This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this control is being called from the wrong thread. You must marshal
to the correct thread using Control.Invoke or Control.BeginIn voke to perform this action.
I have multiple background-threads that returns info about their progress through a Event. This event's handler is then on a Form
that has the responsability to display all the info to the user through a Treeview control.

Earlier in the development i used a textbox to see the data, and it worked without a hitch, but a treeview is a more practical
display.

The exception occurs when i try to add the nodes genereated from the recieved data (an array with some strings) to the Treeview
control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve this?
Nov 21 '05 #1
6 4365
You can manipulate windows forms controls only from the thread that created
the controls which is almost always the main application thread. This error
message means you're trying to manipulate a control from another thread. The
only methods you can call on a control from another thread are the
Control.Invoke, Control.BeingIn voke and Control.EndInvo ke (and I think
CreateGraphics also). I believe you're calling treeStatus.Node s.Add(tNode)
from a different thread than the one that created the treeview. A couple of
articles on how to use delegates and Control.Invoke:
http://www.devx.com/dotnet/Article/11358
http://www.yoda.arachsys.com/csharp/...#windows.forms (this
one's in C# but you should get the idea)
hope that helps..
Imran.

"Jarod_24" <ja******@hotma il.com> wrote in message
news:1096843403 .JPcjOv9ssfBVvy 4qQKwtpg@terane ws...
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this
control is being called from the wrong thread. You must marshal to the
correct thread using Control.Invoke or Control.BeginIn voke to perform this
action.
I have multiple background-threads that returns info about their progress
through a Event. This event's handler is then on a Form that has the
responsability to display all the info to the user through a Treeview
control.

Earlier in the development i used a textbox to see the data, and it worked
without a hitch, but a treeview is a more practical display.

The exception occurs when i try to add the nodes genereated from the
recieved data (an array with some strings) to the Treeview control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve
this?

Nov 21 '05 #2
In addition to Imran,

In my opinion is the current information about threads on MSDN very good.
http://msdn.microsoft.com/library/de...isualBasic.asp

Your problem and solution is as well described there.

I hope this helps as well?

Cor
"Jarod_24" <ja******@hotma il.com>
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this
control is being called from the wrong thread. You must marshal to the
correct thread using Control.Invoke or Control.BeginIn voke to perform this
action.
I have multiple background-threads that returns info about their progress
through a Event. This event's handler is then on a Form that has the
responsability to display all the info to the user through a Treeview
control.

Earlier in the development i used a textbox to see the data, and it worked
without a hitch, but a treeview is a more practical display.

The exception occurs when i try to add the nodes genereated from the
recieved data (an array with some strings) to the Treeview control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve
this?

Nov 21 '05 #3
Strange.
I have made a "Threader" class (in the main thread) that has the responsability to create the threads, adjust priority etc.
All the threads are given a referance back to the Threader class when created, and they use this to ask for permissions to access
resources (files) and to call a method that will raise an event.

I thought that the data was passed on from Thread X to the main thread through this referance to "Threader".
And then "Threader" sends it on to the Form (wich is also a part of the main thread)?
As i said earlier; i had no problems with this when using a textbox.
Here's some example code to show how i've done it.

Public Class Threader
....
Public sub NewThread()
Dim child as new ThreadChild(Me)
Dim t as new Threading.Threa d(AddressOf child.Main)
t.ApartmentStat e = Threading.Apart mentState.MTA
t.Start
End sub

public sub getEventdata(by val list() as string)
'this method is called by the individual threads (no serialization there though)
RaiseEvent MyThreadEvent(l ist)
end sub

End Class

Public class ThreadChild
private MyOwner at threader ' referance set in New()

public sub Main()
'does some stuff here
...
call MyOwner.getEven tdata(mylist)
end sub

End Class

"Imran Koradia" <no****@microso ft.com> wrote in message news:uE******** *****@TK2MSFTNG P11.phx.gbl...
You can manipulate windows forms controls only from the thread that created the controls which is almost always the main
application thread. This error message means you're trying to manipulate a control from another thread. The only methods you can
call on a control from another thread are the Control.Invoke, Control.BeingIn voke and Control.EndInvo ke (and I think
CreateGraphics also). I believe you're calling treeStatus.Node s.Add(tNode) from a different thread than the one that created the
treeview. A couple of articles on how to use delegates and Control.Invoke:
http://www.devx.com/dotnet/Article/11358
http://www.yoda.arachsys.com/csharp/...#windows.forms (this one's in C# but you should get the idea)
hope that helps..
Imran.

"Jarod_24" <ja******@hotma il.com> wrote in message news:1096843403 .JPcjOv9ssfBVvy 4qQKwtpg@terane ws...
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this control is being called from the wrong thread. You must
marshal to the correct thread using Control.Invoke or Control.BeginIn voke to perform this action.
I have multiple background-threads that returns info about their progress through a Event. This event's handler is then on a Form
that has the responsability to display all the info to the user through a Treeview control.

Earlier in the development i used a textbox to see the data, and it worked without a hitch, but a treeview is a more practical
display.

The exception occurs when i try to add the nodes genereated from the recieved data (an array with some strings) to the Treeview
control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve this?


Nov 21 '05 #4
I don't see any of your controls in this code. Where are you trying to add
the nodes to the treeview? Also, how what was the code with the textbox that
you got it to work with?

Imran.

"Jarod_24" <ja******@hotma il.com> wrote in message
news:1096882801 .EVEqYYvhQ0oK4H G4ipEZiw@terane ws...
Strange.
I have made a "Threader" class (in the main thread) that has the responsability to create the threads, adjust priority etc. All the threads are given a referance back to the Threader class when created, and they use this to ask for permissions to access resources (files) and to call a method that will raise an event.

I thought that the data was passed on from Thread X to the main thread through this referance to "Threader". And then "Threader" sends it on to the Form (wich is also a part of the main thread)? As i said earlier; i had no problems with this when using a textbox.
Here's some example code to show how i've done it.

Public Class Threader
....
Public sub NewThread()
Dim child as new ThreadChild(Me)
Dim t as new Threading.Threa d(AddressOf child.Main)
t.ApartmentStat e = Threading.Apart mentState.MTA
t.Start
End sub

public sub getEventdata(by val list() as string)
'this method is called by the individual threads (no serialization there though) RaiseEvent MyThreadEvent(l ist)
end sub

End Class

Public class ThreadChild
private MyOwner at threader ' referance set in New()

public sub Main()
'does some stuff here
...
call MyOwner.getEven tdata(mylist)
end sub

End Class

"Imran Koradia" <no****@microso ft.com> wrote in message

news:uE******** *****@TK2MSFTNG P11.phx.gbl...
You can manipulate windows forms controls only from the thread that created the controls which is almost always the main
application thread. This error message means you're trying to manipulate a control from another thread. The only methods you can call on a control from another thread are the Control.Invoke, Control.BeingIn voke and Control.EndInvo ke (and I think CreateGraphics also). I believe you're calling treeStatus.Node s.Add(tNode) from a different thread than the one that
created the treeview. A couple of articles on how to use delegates and Control.Invoke: http://www.devx.com/dotnet/Article/11358
http://www.yoda.arachsys.com/csharp/...#windows.forms (this one's in C# but you should get the idea)

hope that helps..
Imran.

"Jarod_24" <ja******@hotma il.com> wrote in message

news:1096843403 .JPcjOv9ssfBVvy 4qQKwtpg@terane ws...
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginIn voke to perform this action.

I have multiple background-threads that returns info about their progress through a Event. This event's handler is then on a Form that has the responsability to display all the info to the user through a Treeview control.
Earlier in the development i used a textbox to see the data, and it worked without a hitch, but a treeview is a more practical display.

The exception occurs when i try to add the nodes genereated from the recieved data (an array with some strings) to the Treeview control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve this?



Nov 21 '05 #5
Hi,

I have the same problem that you have had, I did try to use invoke methods but this time I receive target invocation errors. Anyway to get over this?

Onder

on************* **@mikes.com.tr
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this control is being called from the wrong thread. You must marshal
to the correct thread using Control.Invoke or Control.BeginIn voke to perform this action.
I have multiple background-threads that returns info about their progress through a Event. This event's handler is then on a Form
that has the responsability to display all the info to the user through a Treeview control.

Earlier in the development i used a textbox to see the data, and it worked without a hitch, but a treeview is a more practical
display.

The exception occurs when i try to add the nodes genereated from the recieved data (an array with some strings) to the Treeview
control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to solve this?


User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #6
Can I just say, that if you are using threads, you would be well advised to
execute delegates using Invoke, rather than by just raising an event. The
Invoke method will marshal it's execution onto the same thread as the object
you are invoking on.

"Guest" <Guest@aew_nosp am.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have the same problem that you have had, I did try to use invoke methods
but this time I receive target invocation errors. Anyway to get over this?

Onder

on************* **@mikes.com.tr
This is the exception i'm getting:

System.InvalidO perationExcepti on: The action being performed on this
control is being called from the wrong thread. You must marshal
to the correct thread using Control.Invoke or Control.BeginIn voke to
perform this action.
I have multiple background-threads that returns info about their progress
through a Event. This event's handler is then on a Form
that has the responsability to display all the info to the user through a
Treeview control.

Earlier in the development i used a textbox to see the data, and it
worked without a hitch, but a treeview is a more practical
display.

The exception occurs when i try to add the nodes genereated from the
recieved data (an array with some strings) to the Treeview
control itself:

treeStatus.Node s.Add(tNode)

tNode is a node btw with some subnodes, nothing strange there.

That's when the exception occurs, but i still dont understand how to
solve this?


User submitted from AEWNET (http://www.aewnet.com/)

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1248
by: serge calderara | last post by:
Dear all, I have an VB windows application that colect information form a remote database and then populate the tree view with part of the reords. As database data can be huge , I have used the Queeue threading process to colect those information. Then when the callback function is called I populate my treeview with teh return object. As the treeview control is not on the same thread, I have to use the Invoke method.
0
1808
by: Mike Preston | last post by:
Warning - long message. Many thanks for making the A97 version of the treeview w/o activex controls available. I have taken it down a different path and ended up doing almost everything differently. It now has, built in, the ability to have 12 levels, not just 3. The tree's recordsource table (TreeviewRS) is built based on information
1
2360
by: Mitch A | last post by:
I have an app that populates a treeview from a DB. I would like the UI to repaint during this potentially long operation, so I want to spawn a new thread to populate the list. The problem is how to update the treeview from the worker thread without violating the prime directive of Windows programming-Though shalt not operate on a window from other than its creating thread. Can someone point me to a simple implementation of this? Thanks!
0
1313
by: Bobby Owens | last post by:
Hi, I'm current having a problem with the treeview control and multi threading. The treeview is on a form. A request is then sent to a server using IP for the data. The data arrives in an event on a different thread. I have used delegates to allow me to add to the treeview and it all works fine. I cant however seem to set the "SelectedNode" property or the treeview. I have tried directly and also using a delegate. I all cases, the UI...
0
1639
by: Henry | last post by:
I am trying to create a TreeView control that works with an ADO Dataset DataTable or the new BindingSource stuff in .NET 2.0 to build a Treeview that is populated. This is what I came up with so far... I can't run it yet because I don't have the DataTable source... I still want to get some sort of assessment as to whether I am heading in the right direction. Here is the code: ================================ using System;
1
1300
by: Dean Hinson | last post by:
Hello, I am trying to spawn a sunroutine in a worker thread for populating a trreeview. I set the selectednode and then start the thread. However, the thread errors because the selectednode was found to equal "Nothing". Is there some kind of trick to get the threaded subroutine to see the selectednode to process? Thank you inadvance for any assistance.
2
1545
by: casManG | last post by:
I am working on a small project that uses the treeview control in .net 2003. I have a tree view that I am sending to a sub in order to iterate through the nodes. Public Sub test (ByVal inTreeView as Tree View) But, the thing I want to do with the inTreeView requires me to expand all the nodes before I iterate. The problem is that when the sub is complete, the original tree view on my form ends up with all of the nodes expanded I had...
3
1718
by: bg_ie | last post by:
Hi, Lets say I have a TreeView with nodes that represent objects of a number of different types. Is there a way of associating the Set method of each object with its node in the TreeView? That way when you select a node in order to change its associated data, you have easy access to its Set function. The way I normally handel this situation is is to create an enum of all the different types that the treeview contains. I then have a
0
1894
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the current selection and stuff in the tree. I post my code here, any idea ?
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.