Page 1 of 1

Freezing Simulator UI when using callback from javascript to csharp

Posted: Sat Feb 17, 2018 11:38 pm
by hamishebahar
Hi,I'm posting a data from javascript and getting result from javascript to csharp,when I'm using this from simulator it is going to freez Simulator UI but browser is working fine.

here is my code:

Code: Select all

 public static class SignalGoHelper
    {
        public static string HostUrl { get; set; } = "http://host.com/";
        public static void PostData<T>(string url, Action<T> response, params Tuple<string, string>[] parameters) where T : class, new()
        {
            url = HostUrl + url;
            Action<object> callback = (result) =>
            {
                response(Response<T>(result.ToString()));
            };
            CSHTML5.Interop.ExecuteJavaScript(@"var formData = new FormData();
     eval($1);
     jQuery.ajax({
     url : $0,
     method: 'POST',
     xhrFields: { withCredentials: true },
    dataType: 'text',
    crossDomain: true,
   data: formData,
    processData: false,
    contentType: false,
    success: function(data, textStatus, jqXHR){
                 $2(data);
                },
    error: function(jqXHR, textStatus, errorThrown){
                    //if fails     
                }
            });", url, CalculateParameters(parameters), callback);

        }
        static string CalculateParameters(Tuple<string, string>[] parameters)
        {
            StringBuilder result = new StringBuilder();
            foreach (var item in parameters)
            {
                result.AppendLine($"formData.append('{item.Item1}', '{item.Item2}');");
            }
            return result.ToString();
        }
        static T Response<T>(string data) where T : class, new()
        {
            try
            {
                var msg = JsonConvert.DeserializeObject<T>(data, true);
                return msg.Result;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }

Re: Freezing Simulator UI when using callback from javascript to csharp

Posted: Mon Feb 19, 2018 1:12 am
by JS-Support @Userware
Hi,

Thank you for your message.

Do you think you could isolate the issue in a new empty project for us to reproduce it on our machine? If we can reproduce it, we can fix it very quickly.

Thank you again.
Regards,
JS-Support