Design patterns are mainly of three types
Design patterns are mainly of three types
The difference between select and selectMany can be seen when we are accessing data from multilevel classes.
Download Sample Code – 2.62 Kb
In the below example we shall see what exactly is the difference while accessing the properties.
When we access some data by using select it gives us the data that is grouped under the parent (i.e gives multiple arrays). To access the output we need to loop twice.
////This code shows how to use Select()
var Query2 = Builders.Select(Build => Build.Locations);
// Notice that two foreach loops are required to iterate through
// the results because the query returns a collection of arrays.
foreach (List<String> BuildList in Query2)
{
foreach (string builds in BuildList)
{
Console.WriteLine(builds);
}
Console.WriteLine();
}
But using the same sample when we use select many it gives the selected items in one array(i.e it give the output as it is joining all the output from select command)
// Query using SelectMany().
var query1 = Builders.SelectMany(Build => Build.Locations);
// Only one foreach loop is required to iterate through the
// results because it is a one-dimensional collection.
// Select many joins the output of all the sub collections in to one.
foreach (string Loc in query1)
Console.WriteLine(Loc);
When WPF application starts, it actually creates two threads automatically. One is Rendering Thread, which is hidden from the programmer, so you cannot use the rendering thread directly from your program; while the other is Dispatcher Thread, which actually holds all the UI elements. So in other words, you might say Dispatcher is actually the UI thread which ties all the elements created within the WPF application. Conversely, WPF requires all the UI elements to be tied with Dispatcher thread, this is called Thread Affinity. Thus you cannot change any element created on Dispatcher
thread from any other threads, thus it follows the same Win32 based APIs. Thus it allows you to inter-operate any WPF component into HWND
based API. For more, read this. [^]
Dispatcher
is a class that handles thread affinity. It is actually a prioritized message loop through which all elements are channeled through. Every UIElement
is derived from DispatcherObject
which defines a property called Dispatcher
which points to the UI thread. Thus from any other thread, if you want to invoke or access UI component, you need to Invoke using Dispatcher
thread. DispatcherObject
actually has two chief duties, to check and verify if the thread has access to the object.
Create a Custom Routed Event
// Register routed event
public static readonly RoutedEvent SelectedEvent =
EventManager.RegisterRoutedEvent( "Selected", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(MyCustomControl));
// .NET wrapper
public event RoutedEventHandler Selected
{
add { AddHandler(SelectedEvent, value); }
remove { RemoveHandler(SelectedEvent, value); }
}
// Raise the routed event "selected"
RaiseEvent(new RoutedEventArgs(MyCustomControl.SelectedEvent));