Results 1 to 3 of 3

Thread: Question on performance (events vs. timer)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    Question on performance (events vs. timer)

    Greetings to all!

    I have a question about events vs. timers. I want to know what you guys think and/or have experienced. Thank you in advance for reading this!

    I have an object that communicates back and forth with a web service. Now, this object is currently instantiated in all forms where I need to communicate with the web service. This works fine; however, I can have an instance where multiple requests are going off at the same time, even from the same form (I have user controls that asynchronously communicate as well).

    I want to create a "collection" type of class that manages how many requests are being made at a given time (no more than a set limit). The class would hold a collection of these web communicators.

    My question is this. Performance wise (and any other considerations I may not be thinking about), would it be better to have a method on the collection class that raises an event in the communicator object, telling it to communicate, or would it be better to have a timer running in the collection class that every so often (500-1000ms), it checks the queue to see if there are any pending communication requests and fires them off.

    Thoughts?

    Thanks!

    Kyjan
    Last edited by Kyjan; Sep 8th, 2007 at 03:04 PM. Reason: Title was incorrect

  2. #2
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Question on performance (events vs. timer)

    Use an event because every time the event is fired you know something is going in or out of the queue. The timer will cycle forever wasting time if nothing is happening.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    Re: Question on performance (events vs. timer)

    Yes, but what would happen in this scenario?

    1. The program opens and one communication happens.
    2. A screen is opened in the program and 5 communications happen at the same time (5 separate requests for information).

    If the limit is set to 3 communications at a time, then how would I use events to make sure all communications get processed in the queue as well as blocking the code in the calling user control/form from running? (The results of the communication need to go back to the caller for the code to continue.) Wouldn't I need to use timers?

    Kyjan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width