Multi threaded file reading
using System.Threading.Tasks;
static async Task<string> ReadTextFileInBackgroundThread ( string filePath )
{
if( !System.IO.File.Exists(filePath) )
{
Debug.LogWarning($"This file path is invalid tho: '{filePath}'");
return string.Empty;
} // we're still on unity thread here
return await Task.Run(
() =>
{ // we're on worker thread, so exciting!
return System.IO.File.ReadAllText(filePath);
} ); // back on unity thread }
async void Start ()
{
txtText.text =
await ReadTextFileInBackgroundThread( @"c:\hentai\wishlist.txt" );
}