Monday, December 5, 2011

what are the ways available in asp.net to store the session state

ASP.NET session state supports several different storage options for session data. Each option is identified by a value in the sessionstatemode enumeration. The following list describes the available session state modes:

• inProc mode, which stores session state in memory on the Web server. This is the default.

• StateServer mode, which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

• Sql server mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

• Custom mode, which enables you to specify a custom storage provider.

• Off mode, which disables session state.

Wednesday, September 7, 2011

GC check root entity

Garbage collection works by tracking application roots. Application roots are storage locations that contain references to objects on the managed heap (or to null). In .NET, roots are

  1. References to global objects
  2. References to static objects
  3. References to static fields
  4. References on the stack to local objects
  5. References on the stack to object parameters passed to methods
  6. References to objects waiting to be finalized
  7. References in CPU registers to objects on the managed heap

The list of active roots is maintained by the CLR. The garbage collector works by looking at the objects on the managed heap and seeing which are still accessible by the application, that is, accessible via an application root. Such an object is considered to be rooted.

Now suppose that you have a parent form that contains references to child forms and these child forms contain references to the parent form. Further, suppose that the application no longer contains a references to the parent for or any of the child forms. Then, for the purposes of the garbage collector, these managed objects are no longer rooted and will be garbage collected the next time a garbage collection occurs.

Wednesday, August 17, 2011

Const vs. Readonly

const vs. readonly

const and readonly perform a similar function on data members, but they have a few important differences.



const

A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. For example;

public class MyClass {   public const double PI = 3.14159; }

PI cannot be changed in the application anywhere else in the code as this will cause a compiler error.

Constants must be a value type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool), an enumeration, a string literal, or a reference to null.

Since classes or structures are initialized at run time with the new keyword, and not at compile time, you can't set a constant to a class or structure.

Constants can be marked as public, private, protected, internal, or protected internal.

Constants are accessed as if they were static fields, although they cannot use the static keyword.

To use a constant outside of the class that it is declared in, you must fully qualify it using the class name.

A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:

readonly

public class MyClass {   public readonly double PI = 3.14159; }

or

public class MyClass {   public readonly double PI;     public MyClass()   {     PI = 3.14159;   } }

Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example:

public static readonly uint l1 = (uint)DateTime.Now.Ticks;

Notes

  • readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.
  • A readonly member can hold a complex object by using the new keyword at initialization.



static

Use of the static modifier to declare a static member, means that the member is no longer tied to a specific object. This means that the member can be accessed without creating an instance of the class. Only one copy of static fields and events exists, andstatic methods and properties can only access static fields and static events. For example:

public class Car {   public static int NumberOfWheels = 4; }

The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes.

static members are initialized before the static member is accessed for the first time, and before the static constructor, if any is called. To access a static class member, use the name of the class instead of a variable name to specify the location of the member. For example:

int i = Car.NumberOfWheels;


18K白金和黄金谁贵

K白金与铂金的区别。从严格意义上讲,K白金不能等同于铂金。铂金是一种本身即呈天然白色的贵金属,目前是所有首饰贵金属中价格最高的,市场销售的铂金首饰都有“PT”标志,这是铂金的英文缩写。K白金是由黄金和其它金属熔炼而成的白色合金,所谓的18K白金其实是由75%的黄金和25%的其它金属合成的。因此,K白金不可以打上“PT”标志,只能按其纯度打上黄金及纯度的印。 18K是没有白金的,18K是指黄金,之所以是白色,那是因为另外25%的含其它的白色金属,导致是白色,所以称为白色的18K金,不是18K白金,另外因为18K金是含黄金75%,所以业内计算18K金的价格都是按千足金的75%的价格来计算,不过18K金一般会额外的加不少的工费,千足金现在一般是330-380元/克,品牌不同价格区域也不同,瘦的女的,一般佩带千足金黄金的项链5-10克就可以,胖的话就多加些,戒指一般3克4克左右常见。 所以千足黄金贵,18K的便宜

Thursday, August 4, 2011

Get Caller Class

Assuming you were going with something like cfeduke's answer above, you could also add an overload to your LogManager like this:

public static ILog GetLogger() {     var stack = new StackTrace();     var frame = stack.GetFrame(1);     return new Log4NetWrapper(frame.GetMethod().DeclaringType); } 

That way in your code you can now just use:

private static readonly ILogger _logger = LogManager.GetLogger(); 

instead of either of these:

private static readonly ILogger _logger =     LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILogger _logger =      LogManager.GetLogger(typeof(YourTypeName)); 

Which is effectively equivalent of the first alternative (i.e. the one that usesMethodBase.GetCurrentMethod().DeclaringType), only a little simpler.

Thursday, June 30, 2011

比爾蓋茲的十句話,改變你的一生



1 .社會充滿不公平現象。你先不要想去改造它,只能先適應它。
(因為你管不了它)。

2 . 世界不會在意你的自尊,人們看的只是你的成就
在你沒有成就以前,切勿過分強調自尊。
(因為你越強調自尊,越對你不利)。
3 . 你只是中學畢業,通常不會成為CEO,直到你把CEO職位拿到手為止。
(直到此時,人們才不會介意你只是中學畢業)。
4 . 當你陷入人為困境時,抱怨是沒有用的,你只能默默地吸取教訓。
(你要悄悄地振作起來,重新奮起)。
5 . 你要懂得:在沒有你之前,你的父母並不像現在這樣乏味
你應該想到,這是他們為了撫養你所付出的巨大代價。
(你永遠要感恩和孝敬他們,才是道理)。
6 . 在學校裏,你考第幾已不是那麼重要,
但進入社會卻不然。不管你去到哪里,都要分等排名。
(社會、公司要排名次,是常見的事,要鼓起勇氣競爭才對)。
7 . 學校裏有節假日,到公司打工則不然,
你幾乎不能休息,很少能輕鬆地過節假日。
(否則你職業生涯中一起跑就落後了,甚至會讓你永遠落後)。
8 .在學校,老師會幫助你學習,到公司卻不會。
如果你認為學校的老師要求你很嚴格,
那是你還沒有進入公司打工。
因為,如果公司對你不嚴厲,你就要失業了。
(你必須清醒地認識到:公司比學校更要嚴格要求自己)。
9 .人們都喜歡看電視劇,但你不要看,那並不是你的生活。
只要在公司工作,你是無暇看電視劇的。
(奉勸你不要看,否則你走上看電視連續劇之路,而且看得津津有味,那你將失去成功的資格)。
10. 永遠不要在背後批評別人,尤其不能批評你的老闆無知、刻薄和無能。
(因為這樣的心態,會使你走上坎坷艱難的成長之路)。


Thursday, June 23, 2011

Way produce monthly range

Reference : http://stackoverflow.com/questions/711121/whats-the-best-way-to-produce-a-relative-date-range-this-week-this-year-last
public struct DateRange
{
public DateTime Start { get; set; }
public DateTime End { get; set; }
}

public static DateRange ThisYear(DateTime date)
{
DateRange range = new DateRange();

range
.Start = new DateTime(date.Year, 1, 1);
range
.End = range.Start.AddYears(1).AddSeconds(-1);

return range;
}

public static DateRange LastYear(DateTime date)
{
DateRange range = new DateRange();

range
.Start = new DateTime(date.Year - 1, 1, 1);
range
.End = range.Start.AddYears(1).AddSeconds(-1);

return range;
}

public static DateRange ThisMonth(DateTime date)
{
DateRange range = new DateRange();

range
.Start = new DateTime(date.Year, date.Month, 1);
range
.End = range.Start.AddMonths(1).AddSeconds(-1);

return range;
}

public static DateRange LastMonth(DateTime date)
{
DateRange range = new DateRange();

range
.Start = (new DateTime(date.Year, date.Month, 1)).AddMonths(-1);
range
.End = range.Start.AddMonths(1).AddSeconds(-1);

return range;
}

public static DateRange ThisWeek(DateTime date)
{
DateRange range = new DateRange();

range
.Start = date.Date.AddDays(-(int)date.DayOfWeek);
range
.End = range.Start.AddDays(7).AddSeconds(-1);

return range;
}

public static DateRange LastWeek(DateTime date)
{
DateRange range = ThisWeek(date);

range
.Start = range.Start.AddDays(-7);
range
.End = range.End.AddDays(-7);

return range;
}