Dont Do
Work In Progress
Don't do
// Don't Use void without async
[LoginEventAsync(LoginStatus.LoggedIn)]
public void DynamicEventVoid(ILoginSession loginSession, InputField inputField)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
Debug.Log($"Inputfiled {inputField.text}");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 200; i++)
{
stringBuilder.AppendLine($"Adding {inputField.text} : {i}");
var bytes = Encoding.Unicode.GetBytes(stringBuilder.ToString());
using (FileStream fileStream = new FileStream($"{Directory.GetCurrentDirectory()}\\Assets\\void with async file stream {i}.txt", FileMode.Create, FileAccess.Write, FileShare.ReadWrite, bufferSize: 4096, useAsync: true))
{
fileStream.WriteAsync(bytes, 0, bytes.Length);
}
Debug.Log("Done creating text file");
}
stopwatch.Stop();
Debug.Log($"Dynamic void Invoked by Async Method took {stopwatch.Elapsed}");
}
// does not work. cant use GetComponent<> with async
[LoginEventAsync(LoginStatus.LoggedIn)]
public void DynamicEvent(ILoginSession loginSession, GameObject gameObject)
{
Debug.Log($"Cube Name {gameObject.GetComponent<DynamicAttributeEvents>().CubeName}");
Debug.Log("Attempting to modify cube");
gameObject.GetComponent<DynamicAttributeEvents>().CubeName = "Async Invoked";
}
// does not work either, cant access or modify UI/gameobjects on seperate thread other than main
[LoginEventAsync(LoginStatus.LoggedIn)]
public void DynamicEventAsync(ILoginSession loginSession, GameObject gameObject)
{
Debug.Log($"Gameobject Name {gameObject.name}");
gameObject.SetActive(false);
}
// doesnt work with async, exception is most likely thrown but never caught
[LoginEventAsync(LoginStatus.LoggedIn)]
public void DynamicEventVoid(ILoginSession loginSession, InputField inputField)
{
Debug.Log($"Input Filed Value {inputField.text}");
inputField.text = "Text has been changed Dynamically, async invoke but void method";
}
// doesnt throw exception and modifies object on seperate thread without updating main thread
[LoginEventAsync(LoginStatus.LoggedIn)]
public async void DynamicEventAsync(ILoginSession loginSession, InputField inputField)
{
Debug.Log($"Input Filed Value {inputField.text}");
await Task.Run(() => { inputField.text = "Text has been changed Dynamically, Async void"; });
}
// method does not execute after the first debug.log, an exception is most likely thrown but never caught
// if an inputField was already modified on the same thread(not the main thread) then updated values will
// be shown in the Debug.Log() statement. Main thread inputField will not show changes because
// async methods cant modify objects on the main thread(in this scenario, but may be possible with locking)
[LoginEventAsync(LoginStatus.LoggedIn)]
public async Task DynamicEventAwaitAsync(ILoginSession loginSession, InputField inputField)
{
Debug.Log($"Input Filed Value {inputField.text}");
await Task.Run(() => { inputField.text = "Text has been changed Dynamically, async await Task"; });
Debug.Log($"Input Filed Value updated {inputField.text}");
}
Last updated