29 May 2019

c#basics Thread Process

multi

We learned about multi threaded programming in C#. we understood that every program is actually a process which contains threads. there are foreign threads and background threads. there should be at least one foreign thread running in order to keep the process alive. in console application, our program runs in the main thread, which of course is a foreign thread. we can create our own customized threads and start them using the Start command. we saw ThreadStart delegate which does not contain any parameters, and ParameterizedThreadStart delegate which contains an object parameter. we saw we can Abort a thread, and we can also Join a thread to wait for its execution to be completed.

More topics covered:

  • Context switch
  • Thread.Sleep, Thread.Yield
  • Thread.ManagedThreadId
  • Storing threads in a List<Thread>
  • ThreadPool concept

Links:

26 May 2019

c#basics event Enum EnumFlags Attributes

C_Enum

We learned about how the events are implemented inside an interface. we learned about .NET Enum type (Enumerator): Enums expose a list of const values. they are actually integer numbers “behind the scenes”. we saw a variety set of Enum api functions which we can use, such as: Parse, GetValues, etc. We saw the Flags attribute which is used to define the Enum as a multi-selection Enum (using binary 1 and 0). we can use methods like HasFlags and pipe ( | ) operator in order to read and write values of the flag Enum instance

More topics covered:

  • Enum static methods
  • Enum in switch-case
  • Enum as a method argument 
  • Enum as a method return value
  • Enum printed as string
  • Enum GetValues and GetNames
  • Enum.TryParse
  • C# Attributes

Links:

22 May 2019

c#basics event EventHandler OnEvent

delev

We learned about the event keyword and the EventHandler class. we learned the delegate which is defined for the event “behind the scenes” (object sender, EventArgs e). we learned about the EventArgs and saw how to create our own customized EventArgs (inherit from EventArgs).  we saw the naming convention of the event-name ,which should state the scenario in the correct time tense (i.e. VideoEncod-ed, VideoEncod-ing, etc.) . we saw that the Event is fired from a method call On<Event-Name> (in the publisher side); in the subscriber side- we saw that we have to define a method called <Event-name>EventHandler and to register it to the event. we saw that events are different from delegate, for example you cannot override the event using the “=”  operation, but instead- you must use the “+=” operation to add your method. then we saw how WinForm OnClick is registering the event and later on executing it. finally we saw how to register our method into the .NET Timer class and execute it in each interval

More topics covered:

  • delegate Combine
  • using new keyword on delegate
  • delegate BeginInvoke EndInvoke
  • Generic EventHandler<T>
  • Who is the objectsender
  • using this for the object sender

Links:

19 May 2019

c#basics delegate Action Func Lambda-Expression

delev

We learned about the event driven approach and the need of a contract to define a method signature. The .NET message signature type is called delegate and it helps us to store 1 or more methods with the same (exact) signature. Why? so we can Invoke these methods (stored in the delegate) whenever we want to (usually when an event occurs, for example: button-Click). We saw the Action<T> type and the Func<T> type which are actually a delegate wrappers. we understood the loosely couple concept in which we can take two non-related classes and bind them together using the delegate (and unbind them). Finally we saw how to create a delegate method using Lambda expression

More topics covered:

  • Publish-Subscriber
  • Creating Property of a delegate member
  • Using the delegate type as a method parameter
  • Using the delegate type as a method return value
  • Executing delegate using Invoke and without Invoke
  • Delegate can actually store 1 or more methods
  • Invoking a delegate execute all of the stored methods

Links:

Design a site like this with WordPress.com
Get started