Freezing Simulator UI when using callback from javascript to csharp

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
hamishebahar
Posts: 8
Joined: Sun May 22, 2016 2:58 am

Freezing Simulator UI when using callback from javascript to csharp

Postby hamishebahar » Sat Feb 17, 2018 11:38 pm

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;
            }
        }
    }

JS-Support @Userware
Site Admin
Posts: 921
Joined: Tue Apr 08, 2014 3:42 pm

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

Postby JS-Support @Userware » Mon Feb 19, 2018 1:12 am

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


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 2 guests

 

 

cron