I am implementing vivox in unity and I came across a situation in the tutorial where the guy has done something with AsyncCallback
delegate that I want to confirm.
using UnityEngine;
using VivoxUnity;
using System;
public class VivoxLearn : MonoBehaviour
{
VivoxUnity.Client client;
ILoginSession loginSession;
private string issuer="";
private string tokenKey = "";
private string domain = "";
private Uri server=new Uri("");
private TimeSpan timespan = new TimeSpan(90);
private AsyncCallback loginCallback; //check-1
private void Awake()
{
client = new Client();
client.Uninitialize();
client.Initialize();
DontDestroyOnLoad(this);
}
void Start()
{
loginCallback = new AsyncCallback(Login_Result); //check-2
}
public void Login(string username)
{
AccountId accountId = new AccountId(issuer, username, domain);
loginSession.BeginLogin(server, loginSession.GetLoginToken(tokenKey, timespan), loginCallback);//check-3
}
private void Login_Result(IAsyncResult ar) //check-4
{
try
{
loginSession.EndLogin(ar);
}
catch (Exception e)
{
Debug.Log(e.Message);
}
}
}
In line check-3, instead of creating AsyncCallback
delegate(check-1) and passing Login_Result
(check-4) method to delegate(check-2), what if I directly pass Login_Result
as the last argument in line (check-3)? Is that a legit and allowed way? If yes, then please explain a bit that why it is allowed to do so...