|
wow, what a silly mistake!
Thanks!
|
|
|
|
|
Howzit people,
I sit with a very interesting problem and I have the feeling that there is an easier way to do what I want to do. In short, I want to loop through the folders on my machine and build a treeview. Here is the code that I use to do it but it is really slow (Windows form with 2 treeviews named tvwSource and tvwDestination):
<br />
private void MainForm_Load(object sender, EventArgs e) {<br />
string path = System.Reflection.Assembly.GetCallingAssembly().Location;<br />
if (tvwSource.Nodes.Count == 0) {<br />
FillTree(ref tvwSource, path);<br />
}<br />
try {<br />
if (tvwDestination.Nodes.Count == 0) {<br />
foreach (TreeNode treeNode in tvwSource.Nodes) {<br />
tvwDestination.Nodes.Add((TreeNode)treeNode.Clone());<br />
}<br />
}<br />
} catch (Exception) {<br />
}<br />
}<br />
<br />
private void FillTree(ref TreeView bindingTree, string path) {<br />
TreeNode rootNode = bindingTree.Nodes.Add("", "My Computer", "mycomputer");<br />
foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) {<br />
if (driveInfo.DriveType == DriveType.Fixed) {<br />
LoopFolders(driveInfo.RootDirectory, ref rootNode);<br />
}<br />
}<br />
try {<br />
bindingTree.SelectedNode = bindingTree.Nodes.Find(path, true)[0];<br />
} catch (IndexOutOfRangeException) {<br />
if (bindingTree.Nodes.Count > 0) {<br />
bindingTree.SelectedNode = bindingTree.Nodes[0];<br />
}<br />
}<br />
}<br />
<br />
private void LoopFolders(DirectoryInfo directoryInfo, ref TreeNode parentNode) {<br />
try {<br />
TreeNode subNode = parentNode.Nodes.Add(directoryInfo.Name);<br />
DirectoryInfo[] subDirectoryInfoArray = directoryInfo.GetDirectories();<br />
foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfoArray) {<br />
if (0 == (subDirectoryInfo.Attributes & (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Temporary))) {<br />
if (0 < (subDirectoryInfo.Attributes & FileAttributes.Directory)) {<br />
LoopFolders(subDirectoryInfo, ref subNode);<br />
}<br />
}<br />
}<br />
subDirectoryInfoArray = null;<br />
} catch (UnauthorizedAccessException) {<br />
} catch (IOException) {<br />
} finally {<br />
}<br />
}<br />
Does anyone know of a quicker way to loop through all the directories on the filesystem?
I used to be vain.... BUT now I'm perfect!
-- modified at 6:11 Tuesday 18th April, 2006
|
|
|
|
|
|
Hello,
I want to use WebBrowser control in my win application. I am using .Net 2.0 c# At that application I need to restrict user navigation in webbrowser control. For example I want to restrict some links in the site. Could you help me?
Thanks,
e119051
|
|
|
|
|
Use "Navigating" event:
<br />
private void OnNavigating(object sender, WebBrowserNavigatingEventArgs e)<br />
{<br />
if (e.Url.Host.Contains("skipped url"))<br />
{<br />
e.Cancel = true;<br />
}<br />
}<br />
Best regards, Alexey.
|
|
|
|
|
I tested it but it didnt work. And I prepared an extended web browser control and implemented startnavigate event.
Thanks alexey.
Now I will try to control pdf or doc activeX, restricting contex menu and rectricting short keys. I think I will need your help.
|
|
|
|
|
I have a problem with thread priorities, the scenario is shown as the following.
A thread of "Normal" priority(Thread-A) is running, and do AutoResetEvent.WaitOne() after it has started another thread of "Highest" priority (Thread-B). Thread-B will do AutoResetEvent.Set() in the middle of it process.
As I have imagined, Thread-A will not move on until Thread-B has finished completely.
But to my surprise, the Thread-A may soon move on if Thread-B does Set().
Why the thread with the highest priority won't finish before threads of low priority move on.
Thank you.
|
|
|
|
|
Thread priority gives you absolutely no control in which order threads are executed. It's just an indicator that if the processor is fully used that one thread gets more of it than another thread. It might even occur that a low priority thread can finish before a high priority thread just because it makes less calculations. So in your example it's correct behaviour that both threads run parallel - only that Thread-B gets a bit more cpu power. I would even go so far that on dual core processors (assuming no other threads/processes are running beside these two) that the priority would not have any effect at all.
If you want Thread-A to run after Thread-B has finished then Thread-B should call Set() at its very end and not somewhere in the middle.
|
|
|
|
|
Robert Rohde wrote: If you want Thread-A to run after Thread-B has finished then Thread-B should call Set() at its very end and not somewhere in the middle.
I imagined that Windows will work in someway like the behavior of some embedded OS.
Well, it seems that I am wrong.
I will reconsider the constructure of program.
Thank you very much.
|
|
|
|
|
Well it is exactly the same behaviour as the process priority you can set via task manager. If you have a long cpu consuming process (like packing your C harddrive ) which you set to high you can still fire up Calc, calculate something and shut it down - all while a higher priority process is running paralell. Surely it will behave very slow but it still works.
|
|
|
|
|
I see.
Is there anything I should be careful with about the number of threads in a single process?You see, my process doesn't use ThreadPool. Instead, all the threads are invoked just by Thread.Start().
|
|
|
|
|
Even if priority defined the sequence of execution, you still are not guaranteed that the high-priority thread would come to completion after ending the process in the lower priority thread. The reason is that each thread is given a set amount of time to execute. Once that time expires the kernel moves onto the next thread, and so on. Priority defines how long a task will sit in the queue before it gets to run once again. That is why setting a thread to too high of a priority is dangerous. If you have a very tight loop in a thread running at the same level as the OS, you would remain up in the high-eschelon and run more than that OS would.
This gets even hairier if you are doing an interupt specific task (printing, IO, tcpip calls, etc.) since each time you do an interrupt, you get into an even different queue and have to wait for other tasks to complete as well as your interrupt driven task before you get to execute once again.
I suggest doing searches on OS Queue Theory to get a better understanding of queue management. This is OS 101 and operates like this, at a basic level, in any multi-threaded environment. There are entire schools of thread management to determine the most efficient queue management algorithms to make every task run transparent to the thread management while maintaining excellant performance on high priority threads.
|
|
|
|
|
Your reply is very helpful.
Thank you
|
|
|
|
|
You're welcome. IBM's Big Blue was the 'research project' for the queue technology in MVS. You may find researching the chess algorithms for finding the next move. This is the similar approach for determine 'which is the next thread' when processing multi-thread environment.
|
|
|
|
|
Hello,
I want to print directly to parallel port for fast writing (of-course when i use DMPs). I did following code but it generates an exception telling that it can't handle any device:
TextWriter sw = new StreamWriter("LPT1");<br />
sw.WriteLine("This is a test print!"); <br />
sw.Close();
Currently I have working version of it(VB6)
Open "LPT1" For Output As #1<br />
Print #1, "Bla,bla,bla...."<br />
Close #1
and C++
FILE *ptr = fopen("LPT1","w");<br />
fprintf(ptr,"Bla,bla,bla......");<br />
fclose(ptr);
How can I do that? Thanks in advance.
|
|
|
|
|
I’ve finally understand the benefit with using events. I’ve made some my own but have a problem when not subscribing on an event.
public event EventHandler UpdateListCountChangedEvent;<br />
UpdateListCountChangedEvent(this, new EventArgs());
I got an exception (Object reference not set to an instance of an object) in those cases the function UpdateListCountChangedEvent(…) is called and I have no one that listen to it…
_____________________________
...and justice for all
APe
|
|
|
|
|
You must first check if there are any subscribers to the event bvefore raising it...this is usually done with a particular pattern of event/protected method.
public class MyClassWithEvent
{
public event EventHandler MyEvent
protected virtual void OnMyEvent(EventArgs e)
{
if(MyEvent != null)
{
MyEvent(this,e);
}
}
}
The reason its done like this is 2-fold.
1) It enables methods in your class to easily raise the event without worrying if there are any subscribers... so you could have a method in there like:
public void DoSomethingAndRaiseMyEvent()
{
this.OnMyEvent(EventArgs.Empty);
}
2) It enables derived classes to change the behaviour slightly by overriding OnMyEvent.
|
|
|
|
|
Perfect! Thanks!
_____________________________
...and justice for all
APe
|
|
|
|
|
send me the code for creating dynamic checkboxes in html using _javascript
-- modified at 3:18 Tuesday 18th April, 2006
|
|
|
|
|
<script language="JavaScript" type="text/javascript">
document.write("<input type=checkbox>");
</script>
Enjoy !
Best regards, Alexey.
|
|
|
|
|
umaheshchandra wrote: send me the code
Try being polite and asking, rather than demanding.
|
|
|
|
|
How could i add a custom icon to a windows form?
|
|
|
|
|
look for icon property in your form's property window (generally located in right hand side pane of your IDE).
|
|
|
|
|
I have used the icon property before.But the custom icon never appear.i dont know why?
|
|
|
|
|
Hi ,
I have to fill a datatable with data from an ADODB recordset. I am using OleDBDataAdapter's fill method to do so.
The problem is as follows -
There is an adDateTime field in the recordset. Upon calling the fill method, it is converted to System.DateTime. But the 'time' part is lost and i get only date values for all the rows.
Could anybody please help ?
Thanks & Regards, Maau
|
|
|
|