lundi 18 avril 2016

Automatic function linked to an external timer

I have an automatic function, the idea is to execute in an specific time some actions.

It receives a ListView with the actions and specific times.

Actions for automatic

It runs almost pefect. I say almost because sometimes it doesn't executes one action (lets say action #10, and it has 30 actions to do) and when this happen the rest of the actions neither get executed.

I have some validations where I check if the previous actions is executed then the current one is excuted, but it doesn't make any difference, it continues stopping at some point.

Here the code for this automatic function:

Constructor

public RunAutomatic()
{
            InitializeComponent();
            stopwatch = new System.Windows.Forms.Timer();
            stopwatch.Interval = 5;
            stopwatch.Tick += new EventHandler(stopwatch_Tick);
            repSeconds = 0;
            for (int x = 0; x < repeatActions.Capacity; x++)
            {
                repeatActions.Add(x);
                finished.Add(x);
            }
        }

Run Function

private void RunFaster()
{
    if (contPos > 1)
    {
        ArrayList tmp = (ArrayList)repeatActions[contPos - 1];
        if ((bool)tmp[tmp.Count - 1] == true) //This is where it is supposed to validate that the previous action is already executed
            Execute(2);
        else
        {
            contPos = contPos - 1;
            Execute(2);
        }
    }
    else
        Execute(2);
}

I have tried to solve this but can't get over it. Thanks to all replies.

Aucun commentaire:

Enregistrer un commentaire