1

I am trying to create a timer for a Project class (multiple instances) which when elapsed will call a static method from another class (BuildEngine.AddBuild) to add itself (the project) to a build queue.

I get the following error:

Error   4   Method name expected

Build Engine Class:

        // Set timers for builds
        _Logger.Log("Scheduling Builds ...");
        foreach (Project project in _ProjectList)
        {
            switch (project.TriggerType)
            {
                case "Scheduled":
                    TimeSpan nowTime = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0);
                    TimeSpan projectTime = project.Time;
                    project.ProjectTimer = new Timer(nowTime.Subtract(projectTime).TotalMilliseconds);
                    project.ProjectTimer.Elapsed += new ElapsedEventHandler(BuildEngine.AddBuild(project));
                    project.ProjectTimer.AutoReset = true;
                    project.ProjectTimer.Enabled = true;
                    break;
                case "Continuous":

                    break;
            }
        }

BuildEngine.AddBuild():

    public static void AddBuild(Project project)
    {
        Build build = new Build();
        build.Project = project;
        build.BuildNumber = -1;
        build.BuildStatus = BuildStatus.NotBuilding;

        _BuildQueue.Add(build);
    }
1
  • 2
    It sounds like you have code outside a method. You can't do that. Commented Dec 31, 2013 at 20:55

1 Answer 1

3

The signature of the BuildEngine method does not match that of the ElapsedEventHandler delegate, and even if it did, you can't provide parameters to it like that.

Try binding the event to lambda expression (also called an anonymous function) instead:

project.ProjectTimer.Elapsed += (s, e) => BuildEngine.AddBuild(project);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.