Skip to content

Instantly share code, notes, and snippets.

@olegmrzv
Created March 9, 2021 10:50
Show Gist options
  • Save olegmrzv/7758372650518402fce5e71e1dce1f98 to your computer and use it in GitHub Desktop.
Save olegmrzv/7758372650518402fce5e71e1dce1f98 to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
async void Start() {
Debug.Log($"Hi 1 From MainThread {Thread.CurrentThread.ManagedThreadId}");
await Task.Run(async () => {
Debug.Log($"Hi 1 From ThreadPool {Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(TimeSpan.FromMilliseconds(500));
Debug.Log($"Hi 2 From ThreadPool {Thread.CurrentThread.ManagedThreadId}");
}).ContinueWith(_ => Debug.Log($"Hi 2 From MainThread {Thread.CurrentThread.ManagedThreadId}"), TaskScheduler.FromCurrentSynchronizationContext());
Debug.Log($"Hi 3 From MainThread {Thread.CurrentThread.ManagedThreadId}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment