• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

All this await stuff in C#

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    All this await stuff in C#

    I've not MT code in C# for years and when I did it was all the old-fashioned way... basically signals and threads and stuff like in C++.
    The asynchronous revolution broadly passed me by and now I'm writing a MT application... it feels a great opportunity to bone up on the modern way but online resources are muddled depending when they were written.

    Can anyone recommend a book on modern C# for someone who has worked with it but is out of date with this stuff?
    Originally posted by MaryPoppins
    I'd still not breastfeed a nazi
    Originally posted by vetran
    Urine is quite nourishing

    #2
    They got a sale on, courses are £11.99 each. Bargain prices.

    Understand asynchronous programming with .Net and C# | Udemy
    C# Advanced Topics: Prepare for Technical Interviews | Udemy

    Comment


      #3
      Originally posted by DimPrawn View Post
      I never used these sorts of thing, would you endorse them as an experienced developer?
      Originally posted by MaryPoppins
      I'd still not breastfeed a nazi
      Originally posted by vetran
      Urine is quite nourishing

      Comment


        #4
        Books are old school but as everyone has their own level of experience, goals, and desire for learning just google 'c# books' and see what is currently recommended for the level you feel you're at.

        Alternatively start at the beginning as a refresher by binge watching the following:

        c# tutorial for beginners

        102 videos. Shows how the language is broken down so you can seek out more advanced videos or courses for any aspects of particular interest. The 'await/async' stuff is covered in video 101.
        Maybe tomorrow, I'll want to settle down. Until tomorrow, I'll just keep moving on.

        Comment


          #5
          Unless you are doing web page handling, my advice is to not use the await stuff and just do your multithreading the old school way, create and manage your own threads.

          Others will disagree of course.
          Do what thou wilt

          Comment


            #6
            using System;
            using System.Threading.Tasks;

            namespace ConsoleApp1
            {
            class Program
            {
            static async Task Main(string[] args)
            {
            Console.WriteLine("Coronavirus Supermarket visit");
            Coronavirus coronavirus = new Coronavirus();
            Console.WriteLine("Starting looking for essentials ...");
            Task<bool> handSanitiserTask = coronavirus.FindHandSanitiser();
            Task<bool> toiletRollTask = coronavirus.FindToiletRoll();
            await handSanitiserTask;
            Console.WriteLine("Found sanitiser !!!!! ");
            await toiletRollTask;
            Console.WriteLine("Found toilet roll !!!!! ");
            }
            }

            class Coronavirus
            {
            public Coronavirus()
            {
            }

            public async Task<bool> FindHandSanitiser()
            {
            for (int i = 0; i < 10; i++)
            {
            Console.WriteLine("Looking for hand sanitiser");
            await Task.Delay(1000);
            }
            return true;
            }

            public async Task<bool> FindToiletRoll()
            {
            for (int i = 0; i < 10; i++)
            {
            Console.WriteLine("Looking for toilet roll");
            await Task.Delay(2000);
            }
            return true;
            }
            }
            }

            /*
            Example output from a run

            Coronavirus Supermarket visit
            Starting looking for essentials ...
            Looking for hand sanitiser
            Looking for toilet roll
            Looking for hand sanitiser
            Looking for hand sanitiser
            Looking for toilet roll
            Looking for hand sanitiser
            Looking for toilet roll
            Looking for hand sanitiser
            Looking for hand sanitiser
            Looking for toilet roll
            Looking for hand sanitiser
            Looking for hand sanitiser
            Looking for toilet roll
            Looking for hand sanitiser
            Looking for hand sanitiser
            Looking for toilet roll
            Found sanitiser !!!!!
            Looking for toilet roll
            Looking for toilet roll
            Looking for toilet roll
            Looking for toilet roll
            Found toilet roll !!!!!
            */

            Comment


              #7
              Originally posted by SunnyInHades View Post
              <snip>
              If you use the [code]…[/code] tags (the # icon in the editor toolbar) it’ll use a monospace font and retain the whitespace:

              Code:
              using System;
              using System.Threading.Tasks;
              
              namespace ConsoleApp1
              {
                  class Program
                  {
                      static async Task Main(string[] args)
                      {
                          Console.WriteLine("Coronavirus Supermarket visit");
                          Coronavirus coronavirus = new Coronavirus();
                          Console.WriteLine("Starting looking for essentials ...");
                          Task<bool> handSanitiserTask = coronavirus.FindHandSanitiser();
                          Task<bool> toiletRollTask = coronavirus.FindToiletRoll();
                          await handSanitiserTask;
                          Console.WriteLine("Found sanitiser !!!!! ");
                          await toiletRollTask;
                          Console.WriteLine("Found toilet roll !!!!! ");
                      }
                  }
              
                  class Coronavirus
                  {
                      public Coronavirus()
                      {
                      }
              
                      public async Task<bool> FindHandSanitiser()
                      {
                          for (int i = 0; i < 10; i++)
                          {
                              Console.WriteLine("Looking for hand sanitiser");
                              await Task.Delay(1000);
                          }
                          return true;
                      }
              
                      public async Task<bool> FindToiletRoll()
                      {
                          for (int i = 0; i < 10; i++)
                          {
                              Console.WriteLine("Looking for toilet roll");
                              await Task.Delay(2000);
                          }
                          return true;
                      }
                  }
              }
              
              /* 
              Example output from a run
              
              Coronavirus Supermarket visit
              Starting looking for essentials ...
              Looking for hand sanitiser
              Looking for toilet roll
              Looking for hand sanitiser
              Looking for hand sanitiser
              Looking for toilet roll
              Looking for hand sanitiser
              Looking for toilet roll
              Looking for hand sanitiser
              Looking for hand sanitiser
              Looking for toilet roll
              Looking for hand sanitiser
              Looking for hand sanitiser
              Looking for toilet roll
              Looking for hand sanitiser
              Looking for hand sanitiser
              Looking for toilet roll
              Found sanitiser !!!!!
              Looking for toilet roll
              Looking for toilet roll
              Looking for toilet roll
              Looking for toilet roll
              Found toilet roll !!!!!
              */
              OK, you also have to scroll a bit to read it, but nothing’s perfect

              Comment

              Working...
              X