|
Hi,
I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible.
Thanks
Stephen
|
|
|
|
|
StephenMcAllister wrote:
I tried just calling the procedure that loads it and I got a control invoke issue.
Controls should be manipulated in the application thread. At best, you can load your data into an in-memory table or some sort of structure using a thread, then populate the tree in the application thread.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
There's somenthing you can do. I've not done it, but I'm thinking it might be possible.
You can see this article[^] but the main steps are something like this:
public delegate void AddTreeNodeHandler(TreeNode node);
...
void myAddTreeNode(TreeNode node)
{
treeView.Nodes.Add(node);
}
...
MyThread t = new MyThread(treeView, new AddTreeNodeHandler(myAddTreeNode));
Thread t = new Thread(new ThreadStart(t.ThreadMain));
t.Start();
...
class MyThread
{
Control ctl;
AddTreeNodeHandler atn;
void MyThread(Control ctl, AddTreeNodeHandler atn)
{
this.ctl = ctl;
this.atn = atn;
}
void ThreadMain()
{
while(all nodes you need to add)
{
TreeNode node = new TreeNode("text");
ctl.BeginInvoke(atn, new object[] { node });
}
}
}</code> I did it all from the top of my head, without checking docs, and obviously without compiling it, so it might have some mistakes. But it's a good start for what your trying to do.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
|
Hey!
I am looking for some performance gain in my program.
I have a textbox that shows incomming data, this textbox can be set to any size.
Will the textbox take any performance even if its only 5 height and is coverd by an other control, shold i Hide it instead?
BestRegards
SnowJim
|
|
|
|
|
Snowjim wrote:
Will the textbox take any performance even if its only 5 height and is coverd by an other control, shold i Hide it instead?
I honestly can't imagine that this would have even a measurable impact on performance. Even if you're updating the textbox continuously, the OS should only place one repaint message in the message queue. And the screen rendering is often hardware accelerated nowadays. Your best alternative is not to update the textbox at all, or look for other performance improvements.
Why do you think changing the textbox size will have an impact? Have you done any testing that shows some improvement? I'm truly curious.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Quite simply just what the title says.
What i want to do is have all of my files built into the app, but i cant seem to play a music file from the resources so i want to move it to a temporary folder, play it there, then delete it when im done.
|
|
|
|
|
Fine leave me to die... I'll just come back to haunt you, HAUNT YOU ALL I SAY
|
|
|
|
|
Hi,
When my file is right clicked, under the version tab,there are details like file version & language. May i know how to retrieve these details of that file in C# program(without right clicking)
|
|
|
|
|
what kind of file? If it is .NET assembly - reflection. If not, it's Win32 resource (IIRC)... I don't know how to get it from executable... but PE is documented format, right? must be on the web...
e.g here[^]
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I need to find for the files such as bootstrap.exe or instmsiw.exe-installer for the windows installer
|
|
|
|
|
|
|
First question - I've run into what appears to be a very odd behavior. I create a custom type converter based on ExpandableObjectConverter. Assign it to a class using the TypeConverter attribute. Nothing happens - the PropertyGrid displays the property disabled and extracting PropertyDescriptor for it I can see that the converter field is null. What is going on here ? Why was the custom converter not assigned? For a sanity check - if I set the converter to be the base ExpandableObjectConverter then it works fine and the converter is properly assigned.
All the classes are contained within one source file. Perhaps there is some order of instantiation problem going on?
Second question - how do I modify property attributes at run-time? For instance on certain occasions I would like to disable certain properties ( or, if possible - prevent them from being shown in the grid at all ). I can find PropertyDescriptors for each property but all the fields I'm interested in are read-only.
Thanks for any help!
Disclaimer: I'm farily new to C# so excuse my ignorance if the above questions are trivial or just plain dumb
|
|
|
|
|
Hey!
I have the following XML containt
<br />
-<br />
<settings><br />
<Port>0</Port><br />
<StopBits>4</StopBits><br />
<Parity>2</Parity><br />
<BoudRate>9</BoudRate><br />
<DataBits>4</DataBits><br />
<AddTimeStamp>True</AddTimeStamp><br />
<SaveToFile>True</SaveToFile><br />
<SizeOfWindow>MEDIUM</SizeOfWindow><br />
<MountedDisplay>True</MountedDisplay><br />
</settings>
I am using this C# code to fetch it:
<br />
xTR = new XmlTextReader("PortSettings.xml");<br />
xTR.MoveToContent();<br />
<br />
while (xTR.Read())<br />
{<br />
if (xTR.NodeType == XmlNodeType.Element)<br />
{<br />
switch (xTR.Name)<br />
{<br />
case "Port":<br />
MessageBox.Show("Port : " + xTR.ReadElementString("Port"));<br />
break;<br />
case "StopBits":<br />
MessageBox.Show("StopBits : " + xTR.ReadElementString("StopBits"));<br />
break;<br />
case "Parity":<br />
MessageBox.Show("Parity : " + xTR.ReadElementString("Parity"));<br />
break;<br />
case "BoudRate":<br />
MessageBox.Show("BoudRate : " + xTR.ReadElementString("BoudRate"));<br />
break;<br />
case "DataBits":<br />
MessageBox.Show("DataBits : " + xTR.ReadElementString("DataBits"));<br />
break;<br />
case "AddTimeStamp":<br />
MessageBox.Show("AddTimeStamp : " + xTR.ReadElementString("AddTimeStamp"));<br />
break;<br />
case "SaveToFile":<br />
MessageBox.Show("SaveToFile : " + xTR.ReadElementString("SaveToFile"));<br />
break;<br />
case "SizeOfWindow":<br />
MessageBox.Show("SizeOfWindow : " + xTR.ReadElementString("SizeOfWindow"));<br />
break;<br />
case "MountedDisplay":<br />
MessageBox.Show("MountedDisplay : " + xTR.ReadElementString("MountedDisplay"));<br />
break;<br />
default:<br />
break;<br />
}<br />
}<br />
}<br />
xTR.Close();<br />
Problem: It only read Port, Parity, DataBits, SaveToFile and Monted Display. With other words its only reads every other.
Probley this is a simple mistake, pleas help.
Best Regards
SnowJim
|
|
|
|
|
tries the XML file again
<br />
<?xml version="1.0"?><br />
<!--Settings for TerminalSoftware--><br />
<!--By Changing this settings manually could result in instability. <br> This XML file is generated from TerminalSoftware.saveProgramSettings()--><br />
<br />
<settings><br />
<Port>0</Port><br />
<StopBits>4</StopBits><br />
<Parity>2</Parity><br />
<BoudRate>9</BoudRate><br />
<DataBits>4</DataBits><br />
<AddTimeStamp>True</AddTimeStamp><br />
<SaveToFile>True</SaveToFile><br />
<SizeOfWindow>MEDIUM</SizeOfWindow><br />
<MountedDisplay>True</MountedDisplay><br />
</settings>
I know that there is nothing wrong with the XML, it should be the C# code.
|
|
|
|
|
There most be a simple explenation for this, and how to solve it? Else XML will be as good as regular text file in this case.
SnowJim
|
|
|
|
|
Im not 100% sure but I think the ReadElementString function also calls Read internally. Thus every call of this function will result in making the reader moving forward twice.
You could do something like this (although there is probably a more elegant solution):
xTR = new XmlTextReader("PortSettings.xml");
xTR.MoveToContent();
ArrayList neededElements = new ArrayList();
neededElements.Add("Port");
neededElements.Add("StopBits");
neededElements.Add("Parity");
neededElements.Add("BoudRate");
neededElements.Add("DataBits");
neededElements.Add("AddTimeStamp");
neededElements.Add("SaveToFile");
neededElements.Add("SizeOfWindow");
neededElements.Add("MountedDisplay");
while (xTR.Read())
{
if (xTR.NodeType == XmlNodeType.Element)
{
if (neededElements.Contains(xTR.Name)) {
MessageBox.Show(xTR.Name + " : " + xTR.Value);
}
}
}
xTR.Close();
(I only added the ArrayList thing to keep the code short )
|
|
|
|
|
Robert Rohde wrote:
Im not 100% sure but I think the ReadElementString function also calls Read internally
yup, it does call both XmlReader.MoveToContent() and XmlReader.Read .
At least in Rotor, but 99% in MS .NET framework too.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Dont realy understand how this could give me the information that every element have? value is ""
SnowJim
|
|
|
|
|
|
|
Its the same thing with xTR.InnerText.
SnowJim
|
|
|
|
|
How come this works?? (I copied your snippet & XML file + changed MessageBox cuz it's VERY bad way how to debug loops!)
xTR.MoveToContent();
while (xTR.Read())
{
if (xTR.NodeType == XmlNodeType.Element)
{
switch (xTR.Name)
{
case "port":
Console.WriteLine("Port : " + xTR.ReadInnerXml());
break;
case "stopbits":
Console.WriteLine("StopBits : " + xTR.ReadInnerXml());
break;
case "parity":
Console.WriteLine("Parity : " + xTR.ReadInnerXml());
break;
...
for this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<port>0</port>
<stopbits>4</stopbits>
<parity>2</parity>
<boudrate>9</boudrate>
<databits>4</databits>
<addtimestamp>True</addtimestamp>
<savetofile>True</savetofile>
<sizeofwindow>MEDIUM</sizeofwindow>
<mounteddisplay>True</mounteddisplay>
</settings>
gives me output:
Port : 0
StopBits : 4
Parity : 2
BoudRate : 9
DataBits : 4
AddTimeStamp : True
SaveToFile : True
SizeOfWindow : MEDIUM
MountedDisplay : True
Press any key to continue (console app in debug mode)
However I had to change strings in switch... (it's case sensitive)
I was wrong InnerText is property of XmlElement not of XmlReader .
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Thanks alot!
I will not use MessageBox to debug, thats forsure!
But i did manage to read the content another way, but im not sure if its faster or slower.
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("PortSettings.xml");<br />
<br />
XmlNode node;<br />
<br />
node = doc.GetElementsByTagName("Port")[0];<br />
if(node != null)<br />
cbConfigPorts.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("StopBits")[0];<br />
if (node != null)<br />
cbConfigStopBits.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("Parity")[0];<br />
if (node != null)<br />
cbConfigParity.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("BoudRate")[0];<br />
if (node != null)<br />
cbConfigBoudRate.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("DataBits")[0];<br />
if (node != null)<br />
cbConfigBits.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("AddTimeStamp")[0];<br />
if (node != null)<br />
cbConfigAddTimeStampToStream.Checked = bool.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("SaveToFile")[0];<br />
if (node != null)<br />
cbConfigSaveMainstreamToFile.Checked = bool.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("SizeOfWindow")[0];<br />
if (node != null)<br />
changeWindowSize(int.Parse(node.InnerText));<br />
<br />
node = doc.GetElementsByTagName("MountedDisplay")[0];<br />
if (node != null)<br />
incomeLoggDisplay.loggDisplayOnOff = bool.Parse(node.InnerText);<br />
<br />
doc = null;<br />
<br />
This works good to!
Many thanks for your time!
Best Regards
SnowJim
|
|
|
|