Weird timeout issue

.NET Edition of the F-IN-BOX
threecrans
Posts: 2
Joined: Mon Dec 07, 2009 9:53 pm

Weird timeout issue

Postby threecrans » Mon Dec 07, 2009 10:50 pm

The process I am having trouble with is this:

- SWF communicates with .NET code via ExternalInterface.call
- .NET code does something time consuming (image processing, in my particular situation.... but it doesn't matter)
- After processing, .NET code calls FlashMethod_CallFunction to call the SWF to take some action

If the .NET code takes too long, the call to FlashMethod_CallFunction is never acknowledged in the SWF.

I boiled it down to a simple test sample:

.NET Code

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace FInBoxTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            f_in_box__control1.FlashProperty_Movie = [your swf file name];
            f_in_box__control1.FlashMethod_Play();
        }

        private void f_in_box__control1_OnFlashCall(object sender, string request)
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml(request);
            XmlAttributeCollection attributes = document.FirstChild.Attributes;
            string command = attributes.Item(0).InnerText;

            if (command == "doCommunicate")
            {               
                    // pretend I'm doing something time consuming
                    System.Threading.Thread.Sleep(30000);

                    string args = "<arguments><string>done</string></arguments>";
                    string func = "<invoke name=\"communicationComplete\" returntype=\"xml\">" + args + "</invoke>";                                                     
                    f_in_box__control1.FlashMethod_CallFunction(func);                                                     
            }
        }
    }
}


And the SWF code (note, you need to create a button and add it to the stage... call it "btn")

Code: Select all

import flash.external.*;

// wire up callback for f-in-box to swf communication
ExternalInterface.addCallback("communicationComplete", communicationComplete);

// add a button to the stage, call it "btn" and wire up the click
btn.addEventListener(MouseEvent.CLICK, doCommunicate);

// receive response from .NET
function communicationComplete(arg){   
   var tf:TextField = new TextField();
   tf.text = arg;
   this.addChild(tf);
}

// talk to .NET
function doCommunicate(evt){   
   if(ExternalInterface.available){
      ExternalInterface.call("doCommunicate");
   }
}

stop();


Now, comment out the Thread.Sleep call so it returns immediately. You will find it works properly.

Uncomment the code, and the final result is never shown in the SWF. If I debug through the .NET code, it calls FlashMethod_CallFunction, but something happens behind the scenes to cause it to fail.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Tue Dec 08, 2009 7:39 am

Thank you for your question.

Could you please send me compiled SWF to support (at) f-in-box.com to test?

Thank you.
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Tue Dec 08, 2009 8:15 am

What if to create a separate thread that does the something time consuming. Once done -- call FlashMethod_CallFunction.

Could you please check it?

Thank you.
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

threecrans
Posts: 2
Joined: Mon Dec 07, 2009 9:53 pm

Postby threecrans » Tue Dec 08, 2009 5:11 pm

Just did a preliminary test using a seperate thread and it looks like it works.

I will attempt this on my actual project and see if it works there as well.


Return to “.NET Edition”

Who is online

Users browsing this forum: No registered users and 14 guests