LoginSignup
0
0

More than 1 year has passed since last update.

async・await/非同期処理のサンプル

Posted at
検証用C#コード.cs

//Microsoft (R) Visual C# Compiler version 3.4.0-beta4-19562-05 (ff930dec)
//Copyright (C) Microsoft Corporation. All rights reserved.


using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Task<string> task = F1Async();
            Console.WriteLine(task.Result);
        }
        
        static async Task<string> F1Async(){
            Console.WriteLine( "F1 start.");
            var ret = "10";
            
            ret =  await F3Async();
            Task.Run(()=>F2(ret));

            Console.WriteLine ("F1 end. ");
            return "ALL End ret:"+ ret;
        }
        
        static void F2(string ret){
            Console.WriteLine( "F2 [ret from F3orF1?:"+ret+"] start.");            
            Console.WriteLine( "F2 [ret from F3orF1?:"+ret+"] end.");
        }
        
        static async Task<string> F3Async(){
            Console.WriteLine( "F3 start.");
            Thread.Sleep(2000);
            Console.WriteLine( "F3 end.");
            return "-1";
        }
    }
}


オンラインツール:https://rextester.com/

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0