|
Pete many thanks for your instructive detective work. Although you did not find the offending line your methods were very instructive. TNX again.
|
|
|
|
|
I have tested this further and it gets curious-er. I installed a drive that has nothing but MP3 files on it. I went in a command com and issued a “Dir *.mp3 /b /s > test.txt” to create a list of all the files on the drive. I read the file with a text editor and there are 17,247 files listed. Okay I run the program I have been testing and it finds only 16800 files. Here is the code I used to which I introduced a counter with which I report to a message box in order to confirm the exact number in the array. The number in the array agrees with countFiles.
<br />
void DirSearch(string sDir)<br />
{<br />
try<br />
{<br />
foreach (string d in Directory.GetDirectories(sDir))<br />
{<br />
foreach (string f in Directory.GetFiles(d, "*.mp3"))<br />
{<br />
arrText.Add(f);<br />
countFiles++;<br />
}<br />
DirSearch(d);<br />
}<br />
}<br />
catch (System.Exception excpt)<br />
{<br />
Console.WriteLine(excpt.Message);<br />
}<br />
}<br />
Upon examintion of the array in the list box there is also 16,800 files in the list box but I notice that I have a directory for “World” music which is not present in the list. Out of curiosity I change the name of the directory from “World” to “aWorld” and run the program without any other changes. The program reports 17,005 files which reflects the approximate number of files in the “World” directory.
It seems that there is something strange happening in DirSearch that is beyond my feeble mind. Since it will not read anything alphabeticaly beyond “Rock and Roll” could there be some kind of musical prejudice at work? That’s a joke.
|
|
|
|
|
Hi,
I tried your code on .NET 1.1 and it works for me, with some comments:
- I changed *.mp3 into *.*
- I have an arrText that is not touched by another thread;
- I have a listBox1 that is not touched by another thread, and NOT added to the Controls
of some window
- In a second run I added a log line which sends the filename f to my standard log mechanism,
consistsing of logging in a file AND logging in a listbox that is visible on my main form.
I looked for all files on a single partition and managed to get all 37000 of them. So there
seems to be no fundamental limitation that you are hitting.
I guess your trouble is with listBox1, everything else is hard to suspect.
If you run your code in the UI thread, I expect in to work properly (albeit freezing
the UI for a couple of minutes); if you run it in another thread, then:
- on .NET 2.0 it will fail immediately (the cross-thread exception kicks in)
- on .NET 1.1 it will behave unreliably (for the same reason, but not explicitly tested
by the framework).
So I suspect you are using .NET 1.1 and forgot to apply the InvokeRequired & Invoke stuff
that has raised so many messages already on CodeProject...
Can you verify this ?
Luc Pattyn
|
|
|
|
|
Im using Vis 2005 and framework 2.0
|
|
|
|
|
So that tells me you are running your code on the UI thread, and if it hangs, it means
something else in your app does not survive the UI thread to be non-reponsive that long.
IMHO adding SuspendLayout/ResumeLayout (which is basically a performance optimalization)
will speed things up, but does not fundamentally solve your problem. I suspect
your app will still fail once a (much) larger number of mp3 files is present.
You could test this by inserting a Thread.Sleep(several seconds) where you now call DirSearch.
regards,
Luc Pattyn
|
|
|
|
|
Had no problem with the program hanging and there was no error report. Its just that all the files on the drive were not in the array. Removing the listBox1.Items.Add from the directoy search seems to have solved the problem. I just tried it on a drive with 34500 mp3 files and it worked fine.
|
|
|
|
|
You can try this:
List<string> my = new List<string>();
for (int i=0;i<200000;i++)
my.Add("a");
Console.WriteLine("There are {0} elements to my list",my.Count.ToString());
Console.ReadKey();
The result is: 200000
I hope that help you
|
|
|
|
|
We have now built arrays of over 80,000 lines with over 250 chars per line with no problem and written this to a list box. There seems to be no array size limitation or limitation of the list box. We have tracked our problem down to a problem in the "recursive directory search" see recent post.
-- modified at 6:32 Wednesday 17th January, 2007
|
|
|
|
|
I want to assign the results of an SQL ExecuteScalar to an int. Which is fine when the ExecuteScalar returns a value (i.e the paramater sent to the stored procedure caused the SELECT function to find a valid record).
BUT if the paramater does not pass the SELECT procedure a value that is already in the table the assignment to an int causes an exception (as no record was returned).
Can i do this without using a try/catch block?
Thanks.
|
|
|
|
|
Red_Wizard_Shot_The_Food wrote: I want to assign the results of an SQL ExecuteScalar to an int. Which is fine when the ExecuteScalar returns a value (i.e the paramater sent to the stored procedure caused the SELECT function to find a valid record).
BUT if the paramater does not pass the SELECT procedure a value that is already in the table the assignment to an int causes an exception (as no record was returned).
Can i do this without using a try/catch block?
You could return it as an object and then cast it if the object was not null.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
As far as i know you can't do it without using try catch or an if statement which in this case is the same.
Convertion in .Net assumes that the converted value is not null. So any testing should be done prior
assuming your id in base are not zero-valued i have implemented a function that executed the command and return zero if not found or the desired value.
I have implemented something similar for strings also.
|
|
|
|
|
Sarafian wrote: you can't do it without using try catch or an if statement which in this case is the same.
No it isn't. A try/catch adds a heck of a processing overhead if an exception is raised. Since this is not an exceptional case getting the value as an object then testing for null would be the better option.
Sarafian wrote: assuming your id in base are not zero-valued i have implemented a function that executed the command and return zero if not found or the desired value.
Returning magic numbers is not the solution. Testing for null or DBNull.Value is.
It should also be realised that null is not the same as DBNull.Value .
null is returned if the SELECT statement returned nothing at all. DBNull.Value is returned if the SELECT statement found the row and column, but the column was null .
|
|
|
|
|
Thanks. Didn't know the difference.
|
|
|
|
|
please how can i get from that string "80-247-0092-1 Grada Publishing" to one string first code (ISBN) and to second string everythig gehind this isbn code? ... please help me ... again
-----------------------------
Computer is my hell on earth
|
|
|
|
|
If the ISBN is always followed by a space character, you can use: String.Split(new Char[] {' '}, 2)
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi
I was hoping for someone to come out with an idea for a situation i came across..pls bear with me, its a bit long, and i shall explain with code.
this is a sample of my class:
public class Customer<br />
{<br />
private Dictionary<long, Membership> membershipDict;
private Dictionary<long, Address> addressDict;
<br />
public Membership GetMembershipByKey(long key)<br />
{<br />
if (membershipDict.Contains(key))<br />
return membershipDict[key];<br />
}<br />
<br />
public void InsertMembership(Membership membership)<br />
{<br />
if (!membershipDict.Contains(key))<br />
membershipDict.Add(membership.MemberhsipId, membership)<br />
}<br />
<br />
}<br />
My problem is, I would have lots of methods to just retrieve and insert my Dictionaries of memberships and addresses. And there are more of these dictionaries in my Customer Class. I was thinking of replacing these with Generic Method, for example:
public T GetObjectByKey<T>(long key)<br />
{<br />
}
But internally I would need some mechanism to tell me which T is being called. I was thinking of using a Dictionary to keep this info, but its strongly typed, and I cannot use a dictionary to keep a keypair value of Type, and Dictionary<T,K>.
I was thinking of letting my Membership and Address classes inherit from an interface, let's say IModel.
So i would have dictionaries:
private Dictionary<long, IModel> membershipDict;
private Dictionary<long, IModel> addressDict;
so that i can keep a:
Dictionary<System.Type, Dictionary<long, IModel>> typeDict;
but I dont really like this approach. Sorry for the very long explanation, but i hope it explains my dilema. I am looking forward to some great suggestions. Im fairly new with C# and generics. Im just looking for a way to shorten my code. Would hate to have same methods repeating everywhere...
Cheers
|
|
|
|
|
First of all have you thought of subclassing the Dictionary<string,YourObject> ?
For what you are asking two are the simplest ways i see based on what i have understood.
You can use a general function with parameter object or a common base object like BaseMemeberShip for all possible MemberShip objects to be added. Then by using the is Address for example determine to which dictionary you will add it. You can also use GetType()
A second way which probably is the same from the functional scope, is to implement an interface which somehow signals what kind of Membership Object it is you are adding.
|
|
|
|
|
Hi
thanks for the reply. But I dont get what you are saying, either i mis-interpret or u misunderstood my meaning.
I guess what im getting at is for this function
public T GetObjectByKey<T>(long key)<br />
{<br />
Type t = typeof(T);<br />
}
I hope that makes sense....
|
|
|
|
|
HOW CAN I OPEN OPENDIALOG IN CLIENT-SIDE AND LIST FILES AND DIRECTORIES IN CLIENT-SIDE?
ALA QUNAIBI
|
|
|
|
|
DON'T SHOUT !!!
In ASP.NET 2.0, there's a control for this. In 1.1, I believe you had to use the old HTML file input tag.
This belongs in the ASp.NET forum, really.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
Using .Net 2.0
I have created webservices inside a project. These services are in a solution on my machine which I am developing.
To reference these services, I use Add Web Reference, webservices in this solution (Because the services are saved in my local machine).
At what stage should I place these webservices in the virtual directory of a webserver?
Should these webservices be developed in a virtual directory on my local machine as opposed to in the local C drive as it is now?
The intension is that others be able to see these webservices as they are being developed.
For an example, from my machine to reference one of the webservices, this is the path I use:
http://localhost:2144/inTest.asmx
does this mean that other developers to reference this webservice should use:
http://MyMachineName:2144/inTest.asmx
??
Thanks
|
|
|
|
|
fmardani wrote: Should these webservices be developed in a virtual directory on my local machine as opposed to in the local C drive as it is now?
A webservice will always be on your hard drive, it will simply be in a directory that is mapped to a folder in IIS. VS.NET is mapping it for you, it has a web server built in. You should probably leave it where it is, so you can debug it and work on it. Deploy it when you move it to a machine it will run on.
fmardani wrote: does this mean that other developers to reference this webservice should use:
They should probably reference it locally on their machines. If you want it somewhere that people can run it, but not work on it, then you may want to set up a machine to host it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Is there any code for automatic generation of a password.
thnaks
|
|
|
|
|
I haven't seen one but it can't be that hard to create a function that takes a random number and returns a char based on the ascii values you allow.
I think System.Convert.ToChar(int) is probably the function you need from the top of my head.
Russell
|
|
|
|
|
arachnoid wrote: I think System.Convert.ToChar(int) is probably the function you need from the top of my head.
Use it with Math.Random, but you'll end up having a senseless password!!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|