Hello Everyone,
when i was working on the Games that we developed in Flash as UI and .Net
as a backend support, so i came to know one issue from flash side, that is, when
flash call any .Net method then it waits till .net method executes due to this
if .net method is taking some time to execute that time flash got hang for this
time period. So solution for this problem to divide .net method what flash is
calling into different -2 sub methods and call these submethods Asynchronously,
so it will release our main method and flash will not hang.
I tried to put one sample code below for reference, if anyone is having
issue please call me.
Thanks,
Atul Gupta
private delegate void FlashResponseDelegate(string FunctionName);
/// <summary>
/// calling flash event to
.net function
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void
FlashSlotGame_FlashCall(object sender,
AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent
e)
{
FlashResponseDelegate objFlashResponseDelegate =
new FlashResponseDelegate(this.CallFlashFunction);
objFlashResponseDelegate.BeginInvoke(e.request
, new AsyncCallback(this.AsyncResponseForServerCommand),
objFlashResponseDelegate);
}
/// <summary>
/// Method to callback the
Flash method in response to Request of the Flash to .Net
/// </summary>
/// <returns></returns>
private void
CallFlashFunction(string
FlashRequest)
{
switch (FlashRequest)
{
case "RequestInitialString":
this.responsestring = this.GetGameInitials();
responseFuntion = "ResponseInitialString";
break;
case "RequestReveal":
this.responsestring = this.GetSpinResponse();
responseFuntion = "ResponseReveal";
break;
}
FlashSlotGame.CallFunction(this.responsestring);
}
/// <summary>
/// This method is used to
End the Async call
/// </summary>
/// <param name="ar"></param>
internal void
AsyncResponseForServerCommand(IAsyncResult
ar)
{
try
{
System.Runtime.Remoting.Messaging.AsyncResult result =
(System.Runtime.Remoting.Messaging.AsyncResult)ar;
FlashResponseDelegate caller = (FlashResponseDelegate)result.AsyncDelegate;
// Get response for request
command
caller.EndInvoke(ar);
}
catch (Exception
ex)
{
// Writing to the Error
log
LogManager.LogManagerInstanse.WriteErrorLog(ex);
}
}