Easy Code For Vivox
  • Introduction
    • Official Links
    • Getting Started
      • Wheres The Code
      • Setup EasyCode in My Project
    • Setup Demo Scenes
      • Vivox Developer Portal
      • Unity Gaming Services (UGS) Dashboard
    • Things To Consider
    • FAQ
  • Development Info
    • Design Decisions
    • Release Notes
      • v2.0
      • v1.3
      • v1.2
      • v1.1
      • Template
    • Not Supported
  • Easy Code For Vivox
    • How do I setup EasyCode?
      • Setup Your Credentials
    • How do I do this in EasyCode?
      • Login / Logout
        • Login Properties
        • SetTransmissionMode
        • Login Events
      • Join / Leave Channel
        • Audio Channel
          • Audio Channel Events
        • Text Channel
          • Text Channel Events
        • Channel Events
      • Send Messages
        • Message Events
      • Mute / Unmute
        • Mute / Unmute Events
      • Subscribe to User Events
      • Volume / Audio Settings
        • Audio Device Events
      • Text To Speech ( TTS )
        • TTS Events
    • Vivox Access Tokens
      • Unity Cloud Code
    • Supported Vivox Events
      • Callback Methods
    • Folder Structure / Info
      • / Demo Scenes /
      • / Documentation /
      • / Examples /
      • / Plugins /
      • / Resources /
      • / Scripts /
      • / Settings /
    • Common Errors
  • API Info
    • EasySession.cs
    • EasyManager.cs
      • Main Methods
      • Vivox Event Callbacks
    • Easy3DPositional.cs
    • EasyVivoxUtilities.cs
    • EasySettings.cs
    • Extension Methods
      • EasySIPExtensions.cs
      • GameObjectExtensions.cs
      • TTSMessageExtensions.cs
      • UIExtensions.cs
      • VivoxExtensions.cs
      • EasyDebug.cs
    • EasyEvents.cs
  • Dependency Injection
    • Zenject vs Extenject
    • Install Dependencies
    • Inject Classes
  • Dynamic Events
    • Dynamic Events
    • Tests
    • Gotchas
    • Dynamic Async Events
      • Dont Do
    • Event Examples
  • Related Info
    • How do I do this in Vivox?
      • Conference Chat
    • Pre-Processor Directives
    • How to set iOS Info.plist for Unity?
    • Unity Gaming Services
  • The Future
    • Roadmap
    • Todo / Notes / Changelog
Powered by GitBook
On this page
  • Work In Progress
  • Don't do

Was this helpful?

  1. Dynamic Events
  2. Dynamic Async Events

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}");
    }
PreviousDynamic Async EventsNextEvent Examples

Last updated 2 years ago

Was this helpful?