Pages

Search

Monday, December 31, 2012

Async – Await



A new asynchronous programming model introduced in C# 5.0. The programming style using (Async Await) would be as similar as like synchronous programming with slight code changes.
There are other asynchronous programming methods before such as like
1)      APM (Asynchronous Programming Model) – Begin Invoke, End Invoke…
2)      EAP (Event Asynchronous Pattern) – Event is raised after the completion of Asynchronous function.
3)      TAP (Task Asynchronous Pattern) – Using Task library that helps to build a wrapper (task) on the actual function. The status of the task can be fetched from the task object.

The next model is using Async – Await introduced in C# 5.0.
Below is a sample code, with traditional synchronous and latest asynchronous methods,
Synchronous
Function which would take some time (5 seconds) and returns a number.
  private Int32 GetNumber()
        {
            Thread.Sleep(5000);
            return 10;
        }
Asynchronous using Async Await.


        private async Task<Int32> GetNumber()
        {
            //statements are executed in synchronous manner, as long as there is
            //no await statement
            int a = 10;

            //when there is an await statment, which means compiler will understand that
            //it has to wait for the result, but since the method is marked as async hence it returns the
            //control to the calling method without blocking
            return await Task.Run(() =>
                 {
                     Thread.Sleep(5000);
                     return 10;
                 });

            //when the above task is completed, it would run  the next statements again in synchronous manner as long
            //as there is no await statement.
            a = 20;
        }

Caller :
  private async void button1_Click(object sender, EventArgs e)
        {
            Int32 result = await GetNumber();
 }

The similar async – await can be used for the delegate methods which are invoked by the task library.
Below is an example, declaring async delegate methods in a task.

Task<Int32> result1 =  Task.Run(async () =>
                    {
                        await Task.Delay(5000);
                        return 10;
             });

Note :
1)      To enable async- await – asynchronous behavior, the method should be declared as async.
2)      Method declared as async, may or may not have a await statement.
3)      If there is no await statement in a sync method, compiler executes like a synchronous method.
4)      To have a await statement, method should be declared as async .
5)      A async method always returns Task or Task<T> or can be void.

Why should a async method return type always have to be Task or Task<T> or void.

When a async method is invoked, compiler would expect that there could be a piece of code which needs to be asynchronous.
Hence when there is a await statement which might be in the middle of the code block with in the method, compiler will execute from there as a separate till the end of the code block.

Creating a task for this is because, since it has to run asynchronously it will goto the caller when an await statement is identified.
So to monitor the code execution from await statement, the return task handle would help to do.
If it is not required to bother about the further execution which would happen hence not required to handle return type and hence can be void.

Monday, December 17, 2012

4G Network Specifications

4G Network is although still under development, the basis for the upgrade from 3G to 4G service began in the 21 century, companies began to introduce new technologies. New standards such as WiMax and Long Term Evolution (LTE) was listed as 4G, but there is some debate about its status.
4G Specifications

Network for 4G are oriented to the high quality of service and speed of data transfer. The priorities of this standard has better reception with less data discarded, and faster exchange of information. The International Telecommunication Union (ITU), the body that oversees the standards for wireless networks, has stated that major improvements multimedia messaging services, including video services, requires the approval of a new generation.

4G required speed data transmission rates of at least 100 megabits per second, while a user is moving at high speed, such as in a train and one gigabit per second data in a fixed position. ITU also requires rapid transfer between networks without interruption or loss of signal. The phone also has a 4G network using the Internet Protocol (IP) for the transmission of data in transit, rather than a traditional phone.
Trend towards 4G

Several working groups have been established to contribute to the development of 4G networks. The initial development of this technology include WiMax, which is a faster version of data transfer in Wi-Fi ® networks. LTE is a new technology that improves over 3G, but it is not fully compatible with the requirements of the ITU standard for data transmission.

Both were branded as 4G networks, but led to some confusion and disagreement. Since both methods use IP packets, and showed significant improvement compared with the 3G standard, ITU 4G approved labeling. This is related to WiMax and LTE developers to advance to meet official standards for 4G, which has continued to do so.
Update 3G to 4G

The implementation of the 3G network in the world took almost a decade. The ITU expects 4G network was launched in the world market in a more efficient and timely. Improvements between 2G and 3G substantial improvements necessary hardware for mobile devices, while many companies have developed smart phones used for 3G networks to be compatible with the new 4G standard. However, concerns about the stability and security somewhat reduced development ", as service providers to ensure that they want to protect customer information.
4G network before the first

The first wireless networks, called 1G, was founded in 1980. 2G was introduced in the 1990s to allow multiple transmissions to occur communication. The basis of 3G technology was introduced in late 1990 and has been implemented in most of the world in the 21st century. Although the 3G network was the first to give multimedia applications, 4G promises to bring this technology base and expand significantly.

Artificial Intelligence Programmer

To become an artificial intelligence programmer, you should have a strong background in computer science and programming, with a focus on artificial intelligence (AI) programs and methods. You should consider attending a college or university with a computer program, especially those that can provide a wealth of programming experience. Once you have obtained a bachelor's degree, continuing education, with special attention to AI programming, but not always necessary. You can now search for jobs in the private sector as a programmer or the application of artificial intelligence in a college or university.

If you want to be a developer of artificial intelligence in general, you should start to consider what type of education they want. Like other software developers, many who work in artificial intelligence has extensive teaching experience in programming and software. While you may be able to get a lot of knowledge from research and personal study outside of a college or university, it is often easier to learn what you need to know in a classroom environment. They may also find it easier to enter the field with a degree of truth, not only their own training or practice.

A bachelor's degree may be sufficient in some circles, but must take into account a candidate. This type of training can focus more on AI programming, in particular, rather than general courses in programming and software that is usually part of a bachelor. These courses can be exposed to new ideas and methods used effectively in the development of artificial intelligence software. You should also consider doing a PhD, if you are interested in working as a teacher.

Once you have the necessary training to become a developer of artificial intelligence, then you can start looking for opportunities as a programmer. You should look for software that works in different AI systems and hardware developers and software devices may require firmware artificial intelligence. There are also opportunities in other areas, such as the development of video games, which uses AI to create smarter. If you are interested in finding research opportunities, so you might want to consider teaching at a college or university that allows you to search the development of artificial intelligence systems and educate other computer and programming.

What is Software programmers

Software Programmers are the people that use programming languages ​​to write scripts and codes that are required to run the software. There are several ways to become a software developer, depending on the programming station that some want. It may be a software programmer to go to school or technical college completion of a learning experience or software.

Most universities offer programs to prepare students for a career in software programming. If you want to become a computer programmer, it would be useful to get a degree in engineering, mathematics or computer science. Some universities also offer associate degrees and certificates in software programming teams. If you do not want to go to college, start a career in programming a degree or certificate from a technical school.

Another way to be a software programmer is software complete training under an experienced professional. In practice, you will learn the basics of programming languages ​​and advanced programming techniques. Learning typically involves more practical training and real life experience of formal training programs do. Some people end their education after high school, and others can get a certification or a degree before starting to learn.

Some people become software developers eventually learn from their experiences. You can start as a programmer for a hobby, or you can get entry-level jobs for writing code. Developers who choose to build their skills in this way, you can read information publications to further increase their knowledge base. They can also take courses in programming or software tutorials that do not lead to degrees. Although it is possible for you to become a software programmer with this method, some companies do not hire a programmer who has no training.

Following the acquisition of a software programmer, you can find a job where computers are used, including schools, hospitals, government agencies and banks. You can also get a job as a software development and consulting, or you can choose to start your own business planning. Although these activities depend on the needs of your company, most tasks are software programmers in the development, preparation of manuals for the programs they create, test and repair of software and the creation of software updates. The salary of a software varies considerably depending on their training, skills, location, and years of experience.

More about Hardware, Computer, Operating Systems and Software,

What many people think that the computer can be divided into two parts. The first part, the hardware of the computer, are all known physical work teams. The second part of the software, hardware what to do and how. If I had to think of a computer as a living being, the material body that does things like seeing their eyes, lifting and fill your lungs with air, the software would be the mind, interpreting eye image, the arm to pick up objects, and forces the body to fill the lungs with air.

Operating Systems - software that coordinates the system resources and lets you run other programs. Some examples are Windows Vista, Mac OS X and Linux.

Hardware as part of a machine, can not understand two basic concepts: on and off. The concept is called within and outside the field. The software has been developed to make the binary a useful way to tell the computer what to do. Translates concepts and information that people can understand something that really can be done on the computer.

Computer software is usually created by programmers using a programming language. The programmer writes commands in programming language similar to what someone can use in everyday speech. These commands are called source code. Another program called a compiler is used in the source code, change the commands in a language that the computer can understand. The result is a computer-executable program, which is another name for the software.

The software is divided into two major categories of software and system software. The system software is software that allows the hardware to run correctly. Software are programs that allow users to do more than the use of the equipment. Some experts also a third category, the programming software, but others use these programs from one of the above categories.

Some types of software:

Computer Games - a type of entertainment software that has many types. Some of these families are MMO (Massive Multiplayer Online Games), first-person shooter games, action, adventure and RPG.

Driver software - programs that allow your computer to interact with other hardware devices, such as printers, scanners and video.

Educational software - programs and games that teach or give exercises to help you remember the facts. Educational software is varied, and you can learn everything from computer-related activities as input an object of the chemistry of higher education.

Media Player and Media Development Software - software designed to read and / or modification of digital media files such as music and video.

Productivity Software - an old term that refers to any program that allows users to be more productive in a business sense. Word processing, management tools database and presentation software falls into this category.

Thursday, September 13, 2012

IQueryable and IEnumerable

IEnumerable helps to iterate in the collection or list objects as well known.

IQueryable is an interface and also has extension methods one among which is "AsEnumerable".
"AsEnumerable" method returns IEnumerable object.

IQueryable holds expression and return element type beside IEnumerable.

While calling "AsEnumerable" extension method, the expression is evaluated and the result can be enumerable.

So while calling extension methods after "AsEnumerable", they work on the final collection or list (In Memory).

Where as while calling extension methods of "IQueryable", they work on ahead before getting the list.
This could be the case while working on remote data object or database, it would help to apply where or order by clauses ahead on the data using extension methods before getting in memory list (IEnumerable).






Tuesday, August 28, 2012

Pinterest for BlackBerry Playbook and BlackBerry 10

Hello All,

     Today i am very happy because very long time you and me waiting about Pinterest App for BlackBerry Playbook and BlackBerry 10.And now today those time end and i provide you installer file of Pinterest for BlackBerry Playbook and BlackBerry 10.

Download .bar File

Friday, July 20, 2012

Producer-Consumer Problem using TPL and Blocking Collection

.NET 4.0 frameworks, has introduced TPL (Task Parallel Library) that has several advantages in achieving concurrency. Also there are thread safe collections like “ConcurrentQueue”, “BlockingCollection”, “ConcurrentDictionary”, “ConcurrentBag”, etc….

Producer would broadcast the data maybe which should be thread safe, in case if there are multiple producers who post the data.
Consumer reads the data published may be via queue.
At a point of time consumers should know or signaled saying the posting of data is completed by the producers or source.
Below example is considering there are 3 producers (3 tasks) adding numbers from 1 to 100 to queue in parallel.
At the same time, there are 2 consumers (2 tasks) reading numbers from the queue.
So adding and reading happens parallel using 5 tasks (3 for adding, 2 for reading). However when adding is completed, reading tasks should be signaled and that helps consumers to quit from reading data.
For this we use “BlockingCollection”, which is a new thread safe collection class in .NET 4.0.
Enumerator from BlockingCollection, has a feature to pop the item from the collection. Which mean, when we iterate using enumerator of blocking collection, it not only reads the item but also removes the item which is read from the collection. Also it tries to pop the items until it is signaled (calling “CompleteAdding” method).
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
  var queue = newBlockingCollection<int>();
                var producers = Enumerable.Range(1, 3)
                    .Select(_ => Task.Factory.StartNew(
                        () =>
                        {
                            Enumerable.Range(1, 100)
                                .ToList()
                                .ForEach((i) =>
                            {
                                queue.Add(i);
                                Thread.Sleep(100);
                            });
                        }
                        ))
                        .ToArray();

                var consumers = Enumerable.Range(1, 2)
                    .Select(_ => Task.Factory.StartNew(
                        () =>
                        {
                            foreach (var item in queue.GetConsumingEnumerable())
                            {
                                Console.WriteLine(item);
                            }
                        }
                        ))
                      .ToArray();
                Task.WaitAll(producers);
                queue.CompleteAdding();
                Task.WaitAll(consumers);
 Console.WriteLine("Done!");
            }
            catch (Exceptionexp)
            {
                Console.WriteLine("Error : " + exp.Message);
            }
            Console.Read();




Monday, June 18, 2012

Using Tasks in APM


The “FromAsync” method in the Task Framework helps to build Task object from the “Async” methods (APM). Below code is an example of the same.

Also beside, using  “FromAsync” method, “TaskCompletionSource” object helps to set the result in the callback method.
Below code has both as examples.
namespace ConsoleApplication5
{
    class Program
    {
        delegate int delSum(int a, int b);
        static void Main(string[] args)
        {
            try
            {
                delSum oSum = new delSum((a1, a2) =>
                {
                    Thread.Sleep(2000);
                    return a1 + a2;
                });

                //Using "From Async" method to convert APM to TAP
                Task<int> aa = Task<int>.Factory.FromAsync(
                    oSum.BeginInvoke, oSum.EndInvoke, 4, 5, null);
                aa.ContinueWith(t => Console.WriteLine("using from async method " + t.Result));

                //Using "Task Completion Source", to set the task result from IAsyncResult
                TaskCompletionSource<int> source = new TaskCompletionSource<int>();
                oSum.BeginInvoke(8, 9, ar =>
                     {
                         try
                         {
                             source.SetResult(oSum.EndInvoke(ar));
                         }
                         catch (Exceptionexp)
                         {
                             Console.WriteLine("Error : " + exp.Message);
                         }
                     }, null);

                source.Task.ContinueWith(t => Console.WriteLine("using task completion source " + t.Result));
            }
            catch (Exceptionexp)
            {
                Console.WriteLine("Error : " + exp.Message);
            }
            Console.Read();
        }

    }
}



Tuesday, May 15, 2012

Photo Effect App

Hello,

      Now you do more attractive and awesome effect to Photo in BlackBerry Smart Phone  by using  "Photo Effect App".You can download from below link.

      Download.

Monday, April 9, 2012

Optional and Named Parameters – C#


Visual studio 2010 C#, has extended the capability of calling a function with its argument based on name and also can omit the optional parameters which are set with default value in the function declaration.
Below example demonstrates the same.
Program.cs
  class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //calling the function normally
                Console.WriteLine(CaculateArea(10, 20, "Rectangle 1"));

                //calling the function providing only "length" as named parameter and others will be default
                //which are optional
                Console.WriteLine(CaculateArea(length: 100));

                //calling the function sending all the arguments as named parameters whose order need
                //not be same as arguments order in the calling function.
                Console.WriteLine(CaculateArea(name: "Rectangle 2", width: 100, length: 200));
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error : " + exp.Message);
            }
            Console.Read();
        }

        //function which width and name with default values which are like optional parameters.
        //optional parameters should always be declared at the end after the actual parametes.
        static string CaculateArea(int length, int width = default(int), string name = "No Name")
        {
            return string.Format("The area of \"{0}\" is {1}", name, length * width);
        }
    }

Output:



Partial Class and Method


Declaring a class as “partial” enables the developer to extend the capabilities of class to add extra members with in by creating the same partial class in an another file.

Ex:-
I can create below class in “Class1.cs”
  public partial class Class1
    {
        public void Method1()
        {
            Console.WriteLine("Hello this is method1");
        }
    }
I can also create a class with same name (Class1) as below, in “Class2.cs”, which means I am trying to add functions to an existing partial class.
  public partial class Class1
    {
        public void Method2()
        {
            Console.WriteLine("Hello this is method2");
        }
    }
Similarly, partial methods can be declared in a partial class and can be implemented in the specific partial class. Below example demonstrates the same.

Program.cs
    public partial class MyClass1
    {
        public void Met1()
        {
            Console.WriteLine("Method 1");
            Met2();
        }
         partial void Met2();
    }

MyClass.cs

  public partial class MyClass1
    {
        partial void Met2()
        {
            Console.WriteLine("Method 2");
        }
    }

Now when I create instance for “MyClass1” and invoke “Met1”, “Met1” when calls “Met2” it calls the implemented function in specific partial class.
Note: Partial methods cannot be declared with access specifiers and also cannot be invoked from the object of the class directly which in turn can be called in an another function(s).



Friday, April 6, 2012

Using Linq, Lamda and Indexers – Example


Below example is to create a “BookStall” (Collection of books), finding books based on “BookName” or “Price” or “Author Name and Price”.
Created “Indexer” for “BookStall” class which exposes 3 properties that returns the list of books based on “BookName” or “Price” or “Author Name and Price”.
Created a delegate (delWhereClause) in “BookStall” which returns “bool” and accepts “Book”object.
So the three indexers which are meant for different filters in book collection will create lamda expression or delegate object of type (delWhereClause) and send the delegate to a generic method “GetBooks” which applies Linq for the collection and in case of “where” it invokes the delegate which is sent as argument.

Program.cs (Console Application) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Book objBook = null;
                BookStall objBookStall = new BookStall();
                Random objRand = new Random();

                //creating 50 books and adding to book stall
                //setting random price for each book
                for (int i = 0; i < 50; i++)
                    objBookStall.Add(new Book() { Name = "B" + i, Author = "A" + i, Price = (objRand.Next(100, 120)) });

                //Considering a book, whose name is 'B4'
                objBook = objBookStall["B4"].First();

                //Getting book based on Author and Price
                objBook = objBookStall[objBook.Author, objBook.Price].First();

                //Printing the details of "B4"
                Console.WriteLine("Book Details \n " + objBook);

                Console.WriteLine(Environment.NewLine + "Books with same Price : " + objBook.Price + Environment.NewLine);

                //Getting the books which are with similar price in the book stall and printing to Console
                objBookStall[objBook.Price].ForEach((b) =>
                   Console.WriteLine("Book Details \n " + b));

            }
            catch (Exception exp)
            {
                Console.WriteLine("Error : " + exp.Message);
            }
            Console.Read();
        }
    }

    //The book class which has the attributes related to a book
    public class Book
    {
        public string Name;
        public int Price;
        public string Author;
        public override string ToString()
        {
            return ("Book Name : " + this.Name + ", Price : " + Price + ", Author : " + Author);
        }
    }

    //Bookstall class - List of Books
    public class BookStall : List<Book>
    {
        public delegate bool delWhereClause(Book argBook);

        //Getting books based on Book Name
        public List<Book> this[string BookName]
        {
            get
            {
                return GetBooks(
                    (b) =>
                    {
                        return (b.Name.Trim().ToLower() == BookName.Trim().ToLower());
                    }
                    );
            }
        }

        //Getting books based on Price
        public List<Book> this[int Price]
        {
            get
            {
                return GetBooks(
                    new delWhereClause((b) =>
                        {
                            return (b.Price == Price);
                        }
                        ));


            }
        }

        //Getting books based on Author
        public List<Book> this[string AuthorName, int Price]
        {
            get
            {
                return GetBooks(b => b.Author.Trim().ToLower() == AuthorName.Trim().ToLower() && b.Price == Price);
            }
        }

        //Getting list of books which, invoke the where claus delegate while itterating through each book
        //in the current collection
        private List<Book> GetBooks(delWhereClause argWhereClause)
        {
            return (from b in this where argWhereClause(b) select b).ToList();
        }
    }
}

Output: