• 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!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "All this await stuff in C#"

Collapse

  • NickFitz
    replied
    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

    Leave a comment:


  • SunnyInHades
    replied
    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 !!!!!
    */

    Leave a comment:


  • Dark Black
    replied
    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.

    Leave a comment:


  • Hobosapien
    replied
    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.

    Leave a comment:


  • d000hg
    replied
    Originally posted by DimPrawn View Post
    I never used these sorts of thing, would you endorse them as an experienced developer?

    Leave a comment:


  • DimPrawn
    replied
    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

    Leave a comment:


  • d000hg
    started a topic All this await stuff in C#

    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?

Working...
X