.Net Bug with threads ?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I finally managed to reproduce this bug that gave me much trouble !

    It seems it only appears using threads, that's why this script might seem mad (I have MMF launch a Main function which launches a new thread which launches another one regularly). The problem happens when I try to retrieve a parameter from an immediate condition : from times to times, it doesn't return the specified param.

    Launch the app, press space and watch the result, most of the lines are correctly written ("Condition Parameter : my parameter"), others might show the bug("à§îCondition Parameter : my parameter" or such). If this doesn't show up the first time, press space again, it happens from time to time.

    Is there a way to prevent this from happening (I really need multi-threading) ? Is it because of .Net extension, or should I use Mutex or something ?

  • I dare say, this has to do with mmf's runtime not being really meant to deal with multiple threads.
    It also has to do with how the extension temporarily stores an 'Interaction Condition's parameter(s). (mostly)

    I'll add this as something to fix in a future version.

    Put a lock around the CallImmediateCondition() line. That should solve your problem.

  • Thanks for the help, and fast answer.

    I wasn't able to fix the problem, but i've never used locks before, maybe I did something wrong. Should this be ok ?

    Quote

    string[] param=new string[1]{"my parameter"};
    lock (param){
    MMFInterface.Conditions.CallImmediateCondition("Condition",param);
    }

    It doesn't seem to work.

  • No that's not ok cause you're creating a new object each function, which is useless.
    Create a static object in the BackForth class, a module-level declaration (make sure it's instantiated).
    Then get a lock on that.
    That way, if you've got 1000 threads all going on at once, they're all trying to get a lock on the same variable, so they won't step on eachother's toes. So to speak.


    Code
    class BackForth {
       static Object o = new Object();
       ...
    Code
    public static void test() {
       	lock (o)
    	{	
    	    MMFInterface.Conditions.CallImmediateCondition("Condition",new string[1]{"my parameter"});
    	}
       }
  • I've noticed some strange characters still appear sometimes, but at least it doesn't crash anymore.
    I think this is mmf2's fault or the rich edit box's fault. If you instead, add the returned parameter to a listbox, the problems seem to go away.

  • I never had a crash here...

    Using the list object makes things better, but it's not perfect yet, sometimes a line is not added (this only happened to me once, with more than 4000 immediate conditions, so this might be hard to reproduce).

    Do you still think this issue could be fixed in a future version ?

  • I hope this gets fixed some way, I'd love to see a C# multithreaded server available for MMF, and it will need to be reliable.

    For now I'll stick to the List object to retrieve my parameters. By the way, it would be handy to have a "Last triggered ImmediateCondition Name" expression : this way you could create a "ParamParser" Loop which could retrieve the parameters of any ImmediateCondition (I know it's easy to have a string keep this information, but it would be easier).

  • After working a bit on this problem, i found a workaround :

    The problem is that you can only use CallImmediateCondition() from MMF thread, so I stored every event that should trigger such a callback in a container, and asked MMF to Always CallFunction("TriggerConditions",""). This way, all the ImmediateConditions will be called from inside MMF thread. Here is a simple example :


    This seems to work perfectly here, without any list object to retrieve the params

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!