Results 1 to 3 of 3

Thread: Timers and Threading

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163

    Timers and Threading

    This is going to sound like an odd question.... but does anyone know if, in VB.NET (and the rest of the CLR) timers spawn new threads of execution when they're instantiated?

    I'm asking basically in reference to the Outlook Add In post I made. I tried eliminating the timer that was driving the whole thing and put in a loop... but a loop would basically prevent the addin from ever letting Outlook fully load. THe user wouldn't be able to do anything but stare at Outlook with an hourglass. This is because the thread that Outlook was running on was busy.

    However, using a loop like that all of my objects worked properly.... Using a timer, the object's properties said "Error: Unable to retrive data" in the watch window. Using a seperate thread for the timer to execute on had the same effect.

    My theory is that by instantiating a timer object you create a seperate thread containing whatever code you're using in the elapsed event. That way the main execution thread of your program isn't interupted by the fact that you've got what esentially is a loop checking to see if X amount of time has passed since it's last execution.


    Anyone? Anyone? Beuhler?

    Eiredrake

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Yes, the timer object has to be on its own thread, otherwise it would halt execution of your app when you start it. (just like your loop does)

    In VB6 it was the same way. As a matter of fact, you have to use the timer object to do multi-threading in VB6. I have done it successfully, but it is very confusing.

    But when the timer fires, it calls a method on your first thread. It seems like it is all doing it on one thread, but it isn't.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163

    Interesting

    That explains what's going on with the outlook objects that I'm using.....and some other class objects I was using in another project.


    Basically I'd instantiated everything in the main thread.... and used a timer to fire events which modified those objects. No wonder they were coming out frelled up... they were on another thread.


    The question is though... how do I enable myself to grab hold of COM objects on another thread. I don't want to have to instantiate yet another set of objects for an addin... outlook takes up too damned much memory as it is.


    Eiredrake

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