Results 1 to 3 of 3

Thread: Raise event in main thread

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Raise event in main thread

    My form uses MessageQueue.BeginPeek to look for messages on the queue. When one is found, and .PeekCompleted gets raised, I want to raise an event. Due to other objects registered with the event, I need to raise the event on the main thread.

    Is there a proper way to do this? Right now I call a method using Form.Invoke. The method simply raises the event. Just doesn't seem right to me.

    Thanks,
    Mike

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Raise event in main thread

    I'm sorry I don't quite understand whta's going on... but if you want to add one single event to multiple object, you might want to consider event properties?
    look here for an example http://vbforums.com/showthread.php?t=357956
    (ie, in the add{} block you could add the event to multiple objects)

    possibly not what you want but worth a look
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Raise event in main thread

    Well, I'm following the observer pattern like this article describes - not the first part using interfaces, but under the section titled "Observer Pattern in the .NET Framework".

    My issue is I'd like to raise the event in the main GUI thread, and not in the thread where MessageQueue.PeekCompleted happens.

    Since I'm using asynchronous methods, .PeekCompleted is not executing in the main GUI thread. Since this main thread has created other forms, and those forms are registered with the event, if those forms decide to update their UI in response to the event, you run into problems.

    As I said earlier, I'm getting around it by using Form.Invoke. The only thing the invoked method does is raise the event. Just seems not quite right.

    Mike

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