|
as far as that article goes there isn't a single "try" keyword in the entire solution.
there are several static lists/collections but I doubt they could really grow large with only 25 files.
I think I got it: there is a MemoryStream "MStream" inside FileStreamEx, it never gets Disposed().
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Good find. I got too tired to be looking over countless classes that weren't written by the OP and went to bed!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Please show the code again, the way it looks now.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
int i = 0,duration, year;
string artist, title, album, bandname, genre, path;
string delSql = "DELETE * FROM Library";
musLibConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\GeneSys\Library.mdb";
OleDbCommand deleteLib = new OleDbCommand(delSql, musLibConn);
musLibConn.Open();
if (tbMusPath.Text != "")
{
utility util = new utility();
filepaths = Directory.GetFiles(util.getLibPath(), "*.mp3", SearchOption.AllDirectories);
deleteLib.ExecuteNonQuery();
pBar.Visible = true;
foreach(string str in filepaths)
{
lblPath.Text = str;
ID3Info CurrSong = new ID3Info(filepaths[i], true);
artist = CurrSong.ID3v2Info.GetTextFrame("TPE1");
title = CurrSong.ID3v2Info.GetTextFrame("TIT2");
album = CurrSong.ID3v2Info.GetTextFrame("TALB");
string insSql = "INSERT INTO Library(Artist,Title,Album,Path)" +
"VALUES('" + artist.Replace("'", "''") + "','" + title.Replace("'", "''") + "','" +
album.Replace("'", "''") + "','" + str.Replace("'", "''") + "')";
using (OleDbCommand insertLib = new OleDbCommand(insSql, musLibConn))
{
insertLib.ExecuteNonQuery();
}
i++;
}
pBar.Visible = false;
lblNum.Text = Convert.ToString(filepaths.Length);
util.setNoFiles(filepaths.Length);
|
|
|
|
|
Thanks.
Could you tell us approximately how many files are there, and what would be their typical size.
Are there any exceptions thrown while the app runs (I mean before the OutOfMemory of course)?
[ADDED]
Did you check for any errors in the ID3Info class? There is a Clear() method, and Count and List properties that would return the number and the array or errors.
[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
sorry for taking so long.
RIght now there are approximately 2000 files, with the potential for 40,000 at between 3 and 6 mb.
The program runs fine up until I build the database and get the memory exception.
I will try your other suggestion about the filestream class.
|
|
|
|
|
Hi,
the FileStreamEx class has a ReadText method that creates a MemoryStream but never disposes of it.
That is bad. I suggest you replace line 90
return GetEncoding(TEncoding).GetString(MStream.ToArray());
by
string result=GetEncoding(TEncoding).GetString(MStream.ToArray());
MStream.Dispose();
return result;
It is likely that will dramatically improve the situation.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
doing this throws the same exception but from the binaryFrame.cs
|
|
|
|
|
You have the failing app in front of you, no one else has, so you should try and provide all available information, such as:
1. is it better, i.e. are more files being handled than before, how many?
2. everything you have about the exception, including the stack traceback including line numbers.
Anyway, I'm calling it a day now.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Sorry for the vagueness
It is handling less than before, doesnt appear to be handling more than 2 or three now.
Same exception, different place. BinaryFrame.cs Line 31
28 internal BinaryFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
29 : base(FrameID, Flags)
30 {
31 _Data = Data.ReadData(Length);
32 }
StackTrace
at System.IO.FileStreamEx.ReadData(Int32 Length) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\FileStreamEx.cs:line 147
at ID3.ID3v2Frames.BinaryFrames.BinaryFrame..ctor(String FrameID, FrameFlags Flags, FileStreamEx Data, Int32 Length) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\Frames Classes\BinaryFrame.cs:line 31
at ID3.ID3v2.AddFrame(FileStreamEx Data, String FrameID, Int32 Length, FrameFlags Flags) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\ID3v2.cs:line 1120
at ID3.ID3v2.ReadFrames(FileStreamEx Data, Int32 Length) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\ID3v2.cs:line 896
at ID3.ID3v2.Load() in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\ID3v2.cs:line 443
at ID3.ID3v2..ctor(String FilePath, Boolean LoadData) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\ID3v2.cs:line 77
at ID3.ID3Info..ctor(String FilePath, Boolean LoadData) in C:\Users\Jon Henry\Desktop\RoundButtons\ID3Class\ID3Class\ID3Info.cs:line 25
at JukeBox.frmOptions.btnBLib_Click(Object sender, EventArgs e) in C:\Users\Jon Henry\Documents\Visual Studio 2005\Projects\JukeBox\JukeBox\frmOptions.cs:line 116
at System.Windows.Forms.Control.OnClick(EventArgs e)
|
|
|
|
|
First, don't mix case in the same scope. Local variables are usually either camelCase, or PascalCase but doing both is very poor practice, most people use camelCase. Watch the types of your objects, calling ToStrings on strings shows a poor thought process. Also, don't update the GUI in your loop (lblPath.Text = path) it can be part of the problem and most likely will not update with any regularity.
I do not know if this will work but you can try the code below: (Fix any of my typing errors as I typed it in this window), I don't know if JET supports prepared parameters but if it does you can call command.Prepare() before the loop begins.
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO library(artist, title, album, path) VALUES (@artist, @title, @album, @path);"
command.Parameters.Add("@artist", OleDbType.VarChar);
command.Parameters.Add("@title", OleDbType.VarChar);
command.Parameters.Add("@album", OleDbType.VarChar);
command.Parameters.Add("@path", OleDbType.VarChar);
string sqlString = ";
foreach(string path in filePaths){
currentSong = new ID3Info(path, true); //Is this disposable? If so use using(currentSong = new ID3Info(path, true){
command.Parameters["@artist"].Value = currentSong.ID3v2Info.GetTextFrame("TPE1");
command.Parameters["@title"].Value = currentSong.ID3v2Info.GetTextFrame("TIT2");
command.Parameters["@album"].Value = currentSong.ID3v2Info.GetTextFrame("TALB");
command.Parameters["@path"].Value = path;
command.ExecuteNonQuery();
}
|
|
|
|
|
Hey folks,
I am very new to c# and have a small problem.
The problem :
My mainForm loads up in the CenterScreen position, if I open a new form(form2) it currently opens in CenterScreen position as well.
When form2 loads, form1 falls away.
What I'd like to achieve :
If I moved my mainForm before calling form2 up, I would like form2 to appear in the mainForm's last position.
Thanks in advance for any guidance in this matter.
Paulo.
|
|
|
|
|
If form2 is insanciated from form1, then you can set form2's location property after creating form2 but before calling it's show method. Make sure form2's StartPosition is set to Manual.
If not, you could use the project's settings to save the position of form1, and retrieve those settings in form2's constructor.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi Dave,
Thanks for the reply.
Do you think it would be possible if you could write some example code for me, just to get a better understanding of the solutions you have supplied?
Sorry, like I said I am very new to C# and programming in general. :/
Thanks again for the reply.
|
|
|
|
|
This will help you more. Find some keywords here and Google it, it will give you some code, and explain what you are doing.
You need to create an instance of Form2 from Form1. Then get Form1's position, and set Form2's position to the same. Finally, show Form2.
You should be able to get started with those steps.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Thanks so much, will update with my progress.
|
|
|
|
|
The first one is pretty simple. Somewhere in your Form1 code you will have something like this:
Form2 form2 = new Form2();
form2.Show(); Just insert
form2.Location = this.Location;
in between.
The second, you will need to create a setting in your project's properties of type System.Drawing.Point . On each Move event (you'll need to subscribe to the event) handling method in Form1, set your setting:
Properties.Settings.Default.YourSettingName = this.Location; and after the InitializeComponent call in Form2, retrieve the setting:
this.Location = Properties.Settings.Default.YourSettingName;
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi Dave,
I cannot believe how simple this solution really is - thank you so much.
I am still getting to terms with the jargon and so on, I was so close!
private void btnOpenForm2_Click_1(object sender, EventArgs e)
{
if (form2 == null || form2.IsDisposed)
{
form2 = new Form2();
form2.Location = this.Location; < ----- I just had to add this
this.Visible = false;
form2.Show();
}
else
{
MessageBox.Show("form2 already open,showing");
form2.Focus();
}
}
I also had to change form2's start position within the code for form2, to
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
Thanks so much again for the help, I really appreciate it!
|
|
|
|
|
Paulo Toureiro wrote: I also had to change form2's start position within the code
That can be done from the designer instead so it's serialized into the Form2.Designer.cs file automatically.
Paulo Toureiro wrote: Thanks so much again
No problem
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I want to know how to do that. I can use foreach and for loop, but I prefer to use the array class.
Assume I have my array like
int[] arrayData = { 1, 3, 5, 0, 6 };
By using .All generic method, it is possible to do something like that to determine if all elements are zero
arrayData.All
So how can I use the .All to determine if all elements in the array is 0
|
|
|
|
|
The MSDN has samples, but basically you write a predicate method that returns what you want to return. For example, a search method would involve you writing the code that checks each element. Under the hood, it's not much different at the end of the day, the code that runs will use for each to check each element.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
arrayData.All(item => item == 0);
|
|
|
|
|
How do you declare item in this case?
|
|
|
|
|
item is an inline-declared parameter. You shouldn't have to explicitly declare it anywhere. Enumerable.All should be able to determine the type of the parameter at compile-time.
Note: I'm not in front of my compiler right now, but it's possible (?) that you may have to explicitly provide the parameter with a type. In that case, I believe the syntax would be:
arrayData.All((int item) => item == 0); (disclaimer: this is all coming from memory, so I might not be spot-on )
|
|
|
|
|