Click here to Skip to main content
15,894,646 members
Home / Discussions / C#
   

C#

 
GeneralRe: System.StackOverflowException was unhandled Pin
Vikram A Punathambekar21-Apr-08 3:00
Vikram A Punathambekar21-Apr-08 3:00 
GeneralRe: System.StackOverflowException was unhandled Pin
leppie21-Apr-08 4:08
leppie21-Apr-08 4:08 
QuestionRe: System.StackOverflowException was unhandled Pin
cuongmits21-Apr-08 7:36
cuongmits21-Apr-08 7:36 
GeneralRe: System.StackOverflowException was unhandled Pin
Yusuf21-Apr-08 8:21
Yusuf21-Apr-08 8:21 
QuestionRe: System.StackOverflowException was unhandled Pin
cuongmits21-Apr-08 20:27
cuongmits21-Apr-08 20:27 
GeneralRe: System.StackOverflowException was unhandled Pin
Yusuf22-Apr-08 1:35
Yusuf22-Apr-08 1:35 
GeneralMulti threading To my Search Program Pin
shinboxe21-Apr-08 1:39
shinboxe21-Apr-08 1:39 
GeneralRe: Multi threading To my Search Program Pin
J4amieC21-Apr-08 2:15
J4amieC21-Apr-08 2:15 
Gosh this code is a mess! I'm not sure I know where to start in helping you to work through this but here goes:

if (this.InvokeRequired)<br />
{<br />
invokegetdirecotrs inv = new invokegetdirecotrs(this.getDirectors);<br />
this.Invoke(inv, new object[] { dr });<br />
}


Whatever you are doing here it is very wrong. I think you've misunderstood the point of the Invoke method. It would serve you well to go and look up the documentation to this particular method and read through the description and pay extra attention to the examples given. In a nutshell, you use Invoke to marshall a call back to the UI thread - this is the only thread where you will be able to update the UI (In your case fill a matching file into the ListView).

On the subject of filling the listview you should have a method which encapsulates just this functionality. This method will itself take care of the cross-threadedness of your app.

private delegate void AddItemToListViewDelegate(string item);<br />
<br />
<pre>private void AddItemToListView(string item)<br />
{<br />
  if(this.InvokeRequired)<br />
  {<br />
    this.Invoke(new AddItemToListViewDelegate(this.AddItemToListView),item);<br />
    return;<br />
  }<br />
  this.listView.Items.Add(item);<br />
}</pre><br />
<br />
Now you can call this method from any thread and it will take care of marshalling back to the UI. Attantion to the return keyword, this stops execution continuing on the separate thread - this is one of the specific places you've gone wrong in your code.<br />
<br />
As for the rest of the code, you've massively over-complicated it. You dont need the structs and the wierd "processed" property, and you definately dont have to check the filename one char at a time like this (hint: string has a <code>Contains 
method):

comparest = fi[i].Name.ToString();<br />
for (int j = 0; j < comparest.Length - location.Length + 1; j++)<br />
{<br />
if (location == comparest.Substring(j, location.Length))<br />
{<br />
listView1.Items.Add(fi[i].FullName.ToString());<br />
j = comparest.Length;<br />
}<br />
}


Dead | X|

All you really need is a recursive function that does the looking for the search phrase:

private void SearchRecursive(DirectoryInfo dir, string search)
{
  foreach(FileInfo fi in dir.GetFiles())
  {
    if(fi.FileName.Contains(search))
      AddItemToListView(fi.FileName);
  }

  foreach(DirectoryInfo di in dir.GetDirectories())
  {
     SearchRecursive(di,search);
  }
}


Finally, why you fire off 2 threads in the button click I can only imagine, but suffice it to say you only need one and it should call SearchRecursive with the starting directory (new DirectoryInfo("c:\divx")) and the contents of your search textbox (textBox1.Text).

Hope that helps.
GeneralRe: Multi threading To my Search Program Pin
shinboxe21-Apr-08 3:35
shinboxe21-Apr-08 3:35 
GeneralRe: Multi threading To my Search Program Pin
Simon P Stevens21-Apr-08 3:35
Simon P Stevens21-Apr-08 3:35 
GeneralRe: Multi threading To my Search Program Pin
shinboxe21-Apr-08 3:54
shinboxe21-Apr-08 3:54 
GeneralRe: Multi threading To my Search Program Pin
Simon P Stevens21-Apr-08 4:22
Simon P Stevens21-Apr-08 4:22 
GeneralRe: Multi threading To my Search Program Pin
shinboxe21-Apr-08 8:57
shinboxe21-Apr-08 8:57 
Questionhow to know that an internet connection is alive at some instant? Pin
ptr2void21-Apr-08 1:03
ptr2void21-Apr-08 1:03 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
phannon8621-Apr-08 1:16
professionalphannon8621-Apr-08 1:16 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
ptr2void21-Apr-08 1:25
ptr2void21-Apr-08 1:25 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
Pete O'Hanlon21-Apr-08 1:44
mvePete O'Hanlon21-Apr-08 1:44 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
ptr2void21-Apr-08 1:54
ptr2void21-Apr-08 1:54 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
Pete O'Hanlon21-Apr-08 2:00
mvePete O'Hanlon21-Apr-08 2:00 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
Mustafa Ismail Mustafa21-Apr-08 2:02
Mustafa Ismail Mustafa21-Apr-08 2:02 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
J4amieC21-Apr-08 3:15
J4amieC21-Apr-08 3:15 
GeneralRe: how to know that an internet connection is alive at some instant? Pin
Mustafa Ismail Mustafa21-Apr-08 8:13
Mustafa Ismail Mustafa21-Apr-08 8:13 
Generalmake richtextbox transparent Pin
kamalesh574321-Apr-08 0:11
kamalesh574321-Apr-08 0:11 
GeneralRe: make richtextbox transparent Pin
Blue_Boy21-Apr-08 0:36
Blue_Boy21-Apr-08 0:36 
GeneralGet all tables in sql server instance Pin
hdv21220-Apr-08 23:57
hdv21220-Apr-08 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.