Pages

Tuesday, December 2, 2014

NuGet commands


  • PM> Get-Package Entityframework -ListAvailable
  • PM> Update-Package Entityframework
  • PM> Update-Package reinstall Entityframework


async await .NET 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Workshop.Samples {
    using CL=System.Net.WebClient;
    public class TaskSample:SampleBase {
             
        public override string Name {
            get {
                return "Asynch calls";
            }
        }

        public override void Run() {

            DownLoadAsynchSample();

           // DownLoadSample();
           
            //AsyncCall();
            //RunParallelTasksWithWait();
            // RunParallelTasks();

        }

        private void DownLoadSample() {

            CL client=new CL();
           

            var st=   client.DownloadString("http://www.sublimetext.com/support");
            Console.WriteLine("Download data: {0} more",st.Substring(0,200));
            Console.WriteLine("-------------------------");
          

        }
        private async void DownLoadAsynchSample() {
           // var url="http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.2.dmg";
            var url="http://www.sublimetext.com/support";

            CL webClient=new CL();
            Console.WriteLine("Before DownloadStringTaskAsync called");
          var result=   await webClient.DownloadStringTaskAsync(url);

            Console.WriteLine("After DownloadStringTaskAsync called");
           
            Console.WriteLine("Before Result called");

           
            Console.WriteLine("After Result called");


            Console.WriteLine("Download data: {0} more",result.Substring(0,100));

        }
        private async void AsyncCall() {
            Console.WriteLine("Do Async call");
          await  LongProcessAsync(5,"From asyncCall A");
          await LongProcessAsync(5,"From asyncCall B");
          await LongProcessAsync(5,"From asyncCall C");
           LongProcess(4,"Independent call");

            // LongProcessAsync(2,"From asyncCall B");
        }
        private void RunParallelTasksWithWait() {
            var tasks=new List(){
               new Task(() => {
                LongProcess(2,"Process A");
            }),
                 new Task(() => {
                LongProcess(3,"Process B");
            }),
                    new Task(() => {
                LongProcess(4,"Process C");
            }),
            };


            foreach(var task in tasks) {

                task.Start();
                task.Wait();
            }
        }

        private void RunParallelTasks() {
            var tasks=new List(){
               new Task(() => {
                LongProcess(2,"Process A");
            }),
                 new Task(() => {
                LongProcess(3,"Process B");
            }),
                    new Task(() => {
                LongProcess(4,"Process C");
            }),
            };


            foreach(var task in tasks) {

                task.Start();
            }
        }

        public void LongProcess(int seconds,string processName) {
            Console.WriteLine("Starting {0}",processName);
            Thread.Sleep(1000*seconds);
            Console.WriteLine("End {0}",processName);

        }

        public async Task LongProcessAsync(int seconds,string processName) {

            await Task.Run(() => {
                Console.WriteLine("Starting {0}",processName);
                Thread.Sleep(1000*seconds);
                Console.WriteLine("End {0}",processName);
            });



        }
    }
}