|
If this is typical of your "new" company's production code, you're in for a lot of late nights.
The words modular and layering seem to be missing from their vocabulary.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
There is so much more code I have no documentation. Also, I'm trying to move this thread I'm new to the site
|
|
|
|
|
Hmm.
Great puzzle. "Doctor I'm ill" without any detailed symptoms.
Nevertheless I've been looking for the most common sources of OutOfMemoryException:
- properties that get or set themselves recursively; I did not see any user-defined Property.
- functions that call themselves recursively; I did not see any of them (I may have missed one though).
The next suspect would be event handlers that modify something causing ever more events, possibly resulting in an avalanche. Without any description of this beast, that is hard to find.
I have some more comments though:
1.
I see a lot of new Font statements; most if not all of them only generate two different fonts, so I suggest you generate them once, keep them around in two variables, and assign them to a local variable as appropriate.
Now whenever that approach would be impossible, keep in mind that objects offering a Dispose method require that method being called when done to free up unmanaged data; and most graphic objects (including Font) fall in that category.
2.
And now for a big issue:
you are swallowing exceptions; there are lots of try/catch blocks, and yes they always store the exception message (why only the message?) but then that magic secondLevelMsg variable is never looked at??? The author of this is making life extremely hard, exceptions are there to help you in finding what is going wrong. The current code is very good at hiding what might go wrong. Also, exceptions should not be used as the normal way out. Their occurence should be, well, exceptional.
Hope this helps.
|
|
|
|
|
The previous programmer was trying to go for visual basic.net to C# but this part is still in vb anyway you can show how you might clean up I have tried different ways including copy most of the other program with that does full sync with our item database.
|
|
|
|
|
Hi,
FYI: I'm not a moderator here, I don't have the power to hide a message and replace it by "This message has been flagged as potential spam and is awaiting moderation" (which is gone now).
I would appreciate if you gave more information, in particular at what point in the code things start to go wrong. Assuming your code is runnable, you can find out by (1) looking at the display, (2) or using the debugger, or (3) my personal preference: adding logging and reading the log.
I would never undertake a task as big as yours without logging, to me it is the easiest way of making progress. Yes, it needs extra code, but in my experience that pays off from day one. You might want to read about it here: Article: A simple logging scheme[^]
|
|
|
|
|
Some additional thoughts.
What I previously explained about possible causes for OutOfMemoryException are actually possible causes for StackOverflowException. In order to get OutOfMemory (and not StackOverflow), one needs to allocate lots of objects on the heap (not the stack).
There basically are two scenario's possible for OutOfMemory:
[1]. code is recursing abnormally (so it should result in a StackOverflow) but the heap gets exhausted before the stack is exhausted.
If we assume a workspace of 2GB and a stack size of 1MB and a stack frame of say 1KB (mainly used for local variables of the recursing method), one could recurse 1000 times before getting a stack overflow. To exhaust 2GB in less than 1000 recursions, each recursion needs to consume 2MB which is not at all impossible. If you have objects of such size, look for unlimited recursion (property recursion, function recursion, event avalanche, ...).
[2]. Even when code is running normally (I mean without abnormal recursion), too many and/or too large objects might get allocated (or remain allocated). That depends on the size of the problems your program is dealing with, and the efficiency and correctness of your code.
Things to look for are:
- object references might get stored in static lists, keeping the objects alive forever, even when they aren't really needed any more by the program;
- objetcs with a Dispose() method that aren't disposed of keep hold of their unmanaged memory; this applies to almost all GUI objects.
I stand by my suggestion to use logging. You could even log memory usage statistics periodically and/or when creating large objects.
Things that may point you in the right direction:
- does your app remain responsive (i.e. reacting to user interaction) up to the OutOfMemory exception?
- does your app do everything it should do, and only throws OutOfMemory after some time?
- how long does it take your app from seeming dead to actually throw OutOfMemory?
One wild guess: some operations throw an exception of unexpected type; example: Image.FromFile sometimes throws OutOfMemory when it does not understand the file format (ref[^]). So a single bad data file could be the cause of all this trouble... This is a sufficient reason to always properly display or log all Exception information (message AND stack trace) and never swallow an exception.
|
|
|
|
|
XML is not a database-replacement, and loading a real DB in XML will yield problems. You found them. Yay.
For a decent in-memory db, find one on google and pay the license
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
If I wanted to validate a date using the Range attribute...
private DateTime _Birthday;
[Range(typeof(DateTime), "1/2/2004", "3/4/2004", ErrorMessage = "Value for {0} must be between {1} and {2}")]
public DateTime Birthday
{
get { return _Birthday; }
set
{
if (_Birthday != value)
{
_Birthday = value;
RaisePropertyChanged("Birthday");
}
}
}
How would you bind or otherwise handle the Min max dates so they're dynamic? I don't want the Min/max dates to be hardcoded.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You can't put a variable range value in there - the Range parameters must be constant because it is part of the class definition, not the object.
Me? I'd code my own range check in the Setter (or in the Constructor with a private Setter). That can be as dynamic as you want!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Your best option is probably to implement IValidatableObject[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
See 'Range Attribute with 'DateTime example here: [^], but note author's warning: Quote: However, when the Range attribute is used with DateTime fields, the client side validation does not work as expected. We will discuss this in a later session. The next article in the series [^] shows a custom DateRange Attribute the author claims gets around the limitation mentioned in the first article.
Note: I have no experience with ASP/MVC.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Kevin Marois wrote: How would you bind or otherwise handle the Min max dates so they're dynamic? I don't want the Min/max dates to be hardcoded. As an alternative; compile it on the fly[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm curious how compiling some code to a file would work here.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
You can put a placeholder in the code, replace the string with the date, and recompile it every time it changes.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I think the word "bodge" was invented for this concept!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
It works; if you have a better alternative, please explain
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Create your own "date class"; it becomes self-aware and you don't have to worry about "attributes".
Which begged the question: where / how are the "dynamic" date range values originating in the first place?
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
when i insert hebrew on mySql it goes well but when trying to pest hebrew data from winForm is I get "???"
|
|
|
|
|
That's probably more to do with how you are retrieving and displaying it than anything else: "Hebrew" is a part of a characters set, and not all sets will contain the appropriate glyphs for it to display correctly. When it doesn't, one of the displays you get is '?' to indicate it.
The big possibility is that you are storing them in a non-UNICODE column in your DB: If it's NVARCHAR it's OK, if it's VARCHAR then it won't work correctly.
So start by doing "test inserts": use your existing code to insert a "known good" Hebrew phrase string to SQL, and simultaneously convert it to a byte array:
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(myHebrewString);
Then retrieve the same string from the DB (using your existing code) and convert that to a byte array as well.
Compare the strings, and compare the byte arrays. If they are the same then the DB and the store / restore code is fine, so you need to start looking at your display code.
Sorry, but we can't do any of that for you!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I work with mysql VARCHAR utf8_bin and There is no option of NVARCHAR
|
|
|
|
|
Hi,
indeed VARCHAR is OK for MySQL; NVARCHAR is an SQL type (e.g. SQLServer) and doesn't exist in MySQL.
Did you add Charset=utf8; to your connection string? (ref[^])
|
|
|
|
|
it's work well Thank you for your time and your support
|
|
|
|
|
A method returning a string value of html content when using webbrowser control in C# windows Application .I need to extract a specific data from the html table TD which has an id to specify . If some help me to extract the data easily with any methods . Thanks
<table class="userList w990 marginTop10">
<tbody>
<tr>
<th class="w195 whiteFont leftAlign">Status</th>
<td class="even width150" id="status">Active</td>
<th class="w195 whiteFont leftAlign">Name</th>
<td class="even" id="name"> NATESAN</td>
</tr>
</tbody>
</table>
MARTIN
|
|
|
|
|
|
I'm impressed you resisted the urge to link to that StackOverflow answer about parsing HTML with Regex.
Or to quote the shorter version:
- You have a problem.
- You decide to solve it with regular expressions.
- You now have two problems.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|