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 6630799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:27:27+00:00 2026-05-25T22:27:27+00:00

i have this poll class class Poll { public string question { get; set;

  • 0

i have this poll class

class Poll
{
    public string question { get; set; }
    public Timer pollTimer { get; set; }
    public List<string> userVoted { get; set; }
    public Dictionary<string, int> choices { get; set; }
    public bool PollRunning { get; set; }

    public Poll(string question,Dictionary<string,int> choices)
    {
        this.question = question;
        this.choices = choices;
        this.pollTimer = new Timer(15000);
        this.PollRunning = true;
        this.userVoted = new List<string>();
    }

    public string pollResults()
    {
        string temp = "";

        foreach (KeyValuePair<string, int> keyValuePair in choices)
        {
            temp = temp + keyValuePair.Key + " " + keyValuePair.Value + ", ";
        }

        return string.Format("Poll Results: {0}", temp);
    }
}

and I have this code in a StartPool method

    static Dictionary<Channel, Poll> polls = new Dictionary<Channel, Poll>();
public void startPool(Channel channel)
{
            polls.Add(channel, new Poll(question, tempdict));
            polls[channel].pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);
            polls[channel].pollTimer.Start();
}

When this method gets called

    static void pollTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        //do stuff to the poll that called this.
    }

I need know what poll object’s timer is calling this method
so I can do polls[channel].pollTimer.Stop(); and do polls[channel].pollResults();

As it is I have no idea which poll stop and post results for when this runs

i’m willing to post entire solution if that will help you help me.

  • 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-25T22:27:28+00:00Added an answer on May 25, 2026 at 10:27 pm

    The problem with the way you’ve designed the Poll class is that the Poll class doesn’t completely do its job. You require other classes to know how to start and stop polling, meaning half of the polling implementation is inside the Poll class and half of the implementation is outside the Poll class. If you’re going to create a Poll class, hide ALL the implementation details from everyone else.

    Here is what I mean. I would create an event in Poll like this:

    public event EventHandler<ElapsedEventArgs> Elapsed;
    

    In Poll’s constructor, add this line:

    this.pollTimer.Elapsed += pollTimer_elapsed;
    

    and the pollTimer_elapsed looks like this:

    private void pollTimer_elapsed(object sender, ElapsedEventArgs e)
    {
        var han = this.Elapsed;
        if (han != null)
            han(this, e); // Fire the Elapsed event, passing 'this' Poll as the sender
    }
    

    Add a new public method in Poll to start the timer:

    public void Start()
    {
        this.pollTimer.Start();
    }
    

    So now your startPool method looks like this:

    public void startPool(Channel channel)
    {
        polls.Add(channel, new Poll(question, tempdict));
        polls[channel].Elapsed += poll_Elapsed;
        polls[channel].Start();
    }
    
    static void poll_Elapsed(object sender, ElapsedEventArgs e)
    {
        //sender is now a Poll object
        var poll = sender as Poll;
        // Now you can do poll.pollTimer.Stop()
        // Or better yet, add a Stop method to the Poll class and call poll.Stop()
    }
    

    IMHO this approach is slightly better because the Poll object is hiding more of its implementation from external objects. From startPool’s point of view, the Poll class is simpler to use, and you also don’t require anything outside of your Poll class to know about Timers.

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

Sidebar

Related Questions

i have this timer in c#: public class HomeController : Controller { public int
I'm developing a class and I have this structure: class userInfo { public $interval
The domain is like this: class Poll(db.Model): question = db.StringProperty() ... class Choice(db.Model): poll
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have the following problem. I have this pretty class and now I want
I have a class that conforms to UISearchDisplayDelegate and contains a UISearchBar. This view
I have several timers that poll information off the internet. When I get an
I have this string variable call status which is updated by a serial port
Say I have something like this (and I do) class QueBean extends JPanel {

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.