Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:31+00:00 2026-05-23T01:22:31+00:00

Hello yeah I’m asking this question a second time, sorry about that but I

  • 0

Hello yeah I’m asking this question a second time, sorry about that but I don’t know how to bump previous question. I’ll explain more in depth my problem in a more completed example.

Instead of writing like 300+ Event classes in 300 class files which I may have to do if this doesn’t work, so they can do little timed jobs like this example job below in a server project.

What i’m trying to avoid is writing a bunch of classes and simply just write everything more compacted in structure of whatever i’m working on.

To sum it up, i’m mixing 90% functional programming and want to give some function some delayed timed event, without creating the new timed event in a separate class then running back and forth through the files looking how everything is linked up, but this way everything can be seen so you can find bugs and whatnot much faster as everything is right in front of you, kinda like writing loop code, but with delay.

All I have right now is one thread which processes events, deletes events which have been stopped, keeps re-running events which don’t stop after one cycle and of course waiting until some events can be ran.

If anyone knows a better way to do what i’m trying to do maybe some built-in C# Event system? Which is preferably simple.

class Event {
    private Action action;
    private bool stopped;

    public Event(long tick, Action action) {
        this.tick = tick;
        this.action = action;
        this.lastRun = Environment.TickCount;
    }

    public void stop() {
        stopped = true;
    }

    public bool canRun() { //blah ignore just showing what I plan to do
        if (stopped)
            return false;
         return (Environment.TickCount - lastRun) > tick;
    }

    public void run() {
          this.lastRun = Environment.TickCount;
        action();
    }

    //... other methods
}

 

class Test {
    string t;

    public void setT(string t) {
        this.t = t;
    }

    public void stuff() {
        Console.WriteLine(a);
    }
}

 

class ImportantWork {

    public static void Main(string[] args) {
        someDeepMethod();
    }

    void someDeepMethod() {
        Test t = new Test(); 
        t.setT("secondTime");

        //Here is where the problem occurs.

        Server.registerEvent(new Event(5000, () => {
                    this.stop();  //<-- Error how I call this from this new Event instance.
                    stop();  //<-- Also error
                    //Event.stop();  //<-- haha may work if it was static but thats stupid
                    t.stuff();
                    Console.WriteLine("thirdTime");
        }));

        t.setT("firstTime");
        t.stuff();
    }
}

Expected output:
firstTime
…waits 5 seconds…
secondTime
thirdTime

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:22:32+00:00Added an answer on May 23, 2026 at 1:22 am

    I don’t know how you’d be able to do that inline like that. Why can’t you use some kind of set-function and make it two lines?

    MyEvent newEvent;
    Server.registerEvent((newEvent = new MyEvent(5000)));
    newEvent.setAction(() => {
                                 newEvent.stop();
                                 t.stuff();
                                 Console.WriteLine("thirdTime");
                             });
    

    It seems to me like there’s some kind of structural issue with your design. I’m assuming that the example you provided was not actually what you were working with, just a simple example to address the problem you’re having. If it is, however, the example you’re working with why don’t you just add a boolean flag in the constructor to tell the instance whether or not to call this.stop() on itself – instead of requiring it specified in the Action?

    Best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am working with a simulator that uses rcS scripts to boot, this
this may not be an earth-shattering deficiency of python, but i still wonder about
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I was writing a Regular Expression (first time in my life I might
Hello can anybody solve this please I'm creating the object in the action class
Hello I am compiling a program with make but I get the error of
Hello guys first of all apologize for asking such a simple and yet redundant
My question is about memory use and objects in actionscript 2. If I have
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello , I am currently working on the student association's website. The student's association

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.