Posts

Showing posts from July, 2012

GC, Memory, and Multi-Threading in C#

GL to me, my 50th post and is the 1st technical post. if ur a senior programmer u might be bored and r welcomed to comment. lets start. i have something to do around, say, 60 times. (usually 5000 time, *10 sec is 14 hrs) linear, like for, takes say 60 * 10 sec =  10 mins. but if i multi thread it, say 10 at a time in a good cpu i can get to 20 sec or less for all 10 threads, so where done to 2 min (or almost 4 hrs) - cool! so in a basic way to do that would be that : http://bresleveloper.blogspot.co.il/2012/05/muti-threading-in-forforeach-example.html now u should thing hey - says who that after all these threads are finished all this CPU usage and memory gets free? msdn says so : " For the majority of the objects that your application creates, you can rely on the .NET Framework's garbage collector to implicitly perform all the necessary memory management tasks. However, when you create objects that encapsulate unmanaged resources, you must explicitly release the un

c# to MySql DateTime / TimeStamp Format

this is not about how to extract datetime formats from mysql, there r many examples AND if ur using C# / .NET then the VS knows the job and doesn't need ur help. BUT! when i try to put MY datetime to the mysql  - nothing goes there! well, that's cuz i'm not familiar with mysql datetime formats, and yes, i am not using SP, just simple queries. 1 - the format is yyyy-MM-dd hh:mm:ss, that is:      string date = DateTime .Now.ToString( "yyyy-MM-dd hh:mm:ss" ); 2 - TimeStamp: - on INSERT doesn't get value (null - reading-parsing) and wont accept 1970 and earlier 3 - and since any other mistake would NOT resolve in null but something unsolved by me, in an sql query u can only see them like that: SELECT UpdateDate FROM franchise_information WHERE UpdateDate LIKE  '% % '; for C# u'll need this: MySqlDateTime d = r.GetMySqlDateTime(0); anything else would give you EX : "Unable to convert MySQL date/time value to System.DateTime" and t

Insert \r\n into MySql

replace \r\n to \\r\\n. p.s. vs should know how to do it, make sure u dont have a running around '.

cool links

http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer/ http://www.yacoset.com/Home/signs-that-you-re-a-good-programmer http://www.indiangeek.net/wp-content/uploads/Programmer%20competency%20matrix.htm http://mattbriggs.net/blog/2015/06/01/the-role-of-a-senior-developer/ after all this blog is my code-stuff warehouse 

Parallel.For with/update List example, ThreadLocal Explained

FINAL CODE:   Parallel .For(0, lCount, () => new List < int >(), (i, loop, lLocal) =>     {       lLocal.Add(i);       return lLocal;     },     (lFinal) =>     {        lock ( this )        list = list.Union(lFinal.AsEnumerable()).ToList();     }   ); EXPLANATION: did u read MS example and had a hard time? me 2 :) http://msdn.microsoft.com/en-us/library/dd460703.aspx so lets make it simpler: 1 - what we're doing is this    for ( int i = 0; i < nums.Length; i++)       total += ( long )i; 2 - the catch: http://msdn.microsoft.com/en-us/library/dd997392.aspx 3 - the solution - give the loop(s - i'll show u later) a local var to use during the iteration 4 - whats the new loop is doing : Parallel .For< long >(   // <T> is the type that we are working with, here                               summing a long       0, nums.Length,  // begin-end iteration values,          

How To: Not Using app.config

the answer: delete it from the proj tree (of from folder) and then from the .csproj file. TA DAM! the story? well well, again MS don't REALY care about you. why? cause they can't put anywhere a little "don't use/create app.config"!!! my app is using a dll that is importing a general .config file for all kinda stuff like log4net ect. so i changed a FW in my proj and BOOM! no logger! and no way from the VS(10) to remove it or when u press F5 u get "operation can not be complete". same thing about converting a VS10 proj/sln to VS8 - 2 bloody lines in the .csproj file, can't thay handle it?!?