How does multi-threading work in .NET?
There are two main ways of multi-threading which .NET encourages:
To start your own threads with ThreadStart delegates, you should create a new thread "manually" for long-running tasks.
Using the ThreadPool class either directly (using ThreadPool.QueueUserWorkItem) or indirectly using asynchronous methods (such as Stream.BeginRead, or calling BeginInvoke on any delegate).
Use the thread pool only for brief jobs.
Benefits of using the Thread Pool.
Benefits of using the Thread Pool.
The benefits of using a Thread Pool are:
Thread creation and destruction overhead is negated,
Better performance and better system stability.
It is better to use a thread pool in cases where the number of threads is very large.
C# interview questions with answers
How can you check a nullable variable is assigned?
using hasvalue method
what is the syntax of a nullable variable?
Nullable myval=null;
I would like to check a variable as assigned or not. How can we do that?
Declare the variable as Nullable
What are the different compiler generated methods when a .NET delegate is compiled?
Compilation of a .NET delegate results in a sealed class with three compiler generated methods whose parameters and return values are dependent on the delegate declaration. The methods are,
Invoke()
BeginInvoke() and
EndInvoke().
When TimerCallback delegate is used?
Many application have the need to call a specific method during regular intervals. For such situations we can use the System.Threading.Timer type in conjunction with a related delegate named TimerCallback.
Which enumeration defines different PenCap in C#?
LineCap enumeration which defines different pen cap styles as follows,
public enum LineCap
{
Flat, Square, Round, Triangle, NoAncher, SquareAnchor,
RoundAnchor, DiamondAnchor, ArrowAnchor, AnchorMask, Custom
}
What is the use of param keyword in C#?
In C# param parameter allows us to create a method that may be sent to a set of identically typed arguments as a single logical parameter.