User events and Timers
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: User events and Timers

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    78

    Question User events and Timers

    I have an MFC application where periodically a windows timer interrupt occurs and it reads some data from a database for monitoring purposes

    When a user event occurs such as displaying a modal dialog and then subsequently updating the database with a modication - during this period I want to suspend the timers. There is potentially a conflict with what is being read and written now.

    There are 100s of event handlers throughout the application and would be tedious to suspend and resume the timer interrupts before and after the processing for each event handler.

    Is there an easier way to do it?

    Thanks.

  2. #2
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: User events and Timers

    What dialogs are shown? Are they all the same class?
    Best way I could think of is to setup sometime of global mutex.
    During the dialogs constructor, have it lock a mutex, then unlock when it closes.

    During your timer function, have it wait for the mutex to become unlocked before proceeding.

  3. #3
    Join Date
    Apr 2005
    Posts
    78

    Re: User events and Timers

    Quote Originally Posted by jnmacd View Post
    What dialogs are shown? Are they all the same class?
    Best way I could think of is to setup sometime of global mutex.
    During the dialogs constructor, have it lock a mutex, then unlock when it closes.

    During your timer function, have it wait for the mutex to become unlocked before proceeding.
    Yes I had only just come to a similar conclusion. Its very much a multi-threading type problem.

    Most dialogs do not have a common class other than CDialog. So it would seem its going to be alot of changes - possibly by making them all inherit a private class or something like that.
    Thanks.

  4. #4
    Join Date
    Apr 2005
    Posts
    78

    Resolved Re: User events and Timers

    I think I may have found a neat solution for this problem.

    The problem being after one a dialog was closed - what follows can be - many database writes enclosed within a transaction.
    I understand at each db write the application blocks but continues to process windows messages. Where now it would potentially find a timer message and then excute the event handler for this - which would then go off and read the same db while a transaction is still pending.

    The solution, these timer events now just post a unique message in my own queue.
    I then only inspect this queue during the application idle loop.

    So only a small code change.

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center