A difficult Question for me

This is a discussion on A difficult Question for me within the Windows Programming forums, part of the Platform Specific Boards category; Hi My question is like: There are two modules A and B, if in module A (e.g. push a button), ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Unhappy A difficult Question for me

    Hi

    My question is like:

    There are two modules A and B, if in module A (e.g. push a button), it sends a flag = true to module B where there is while loop:
    Code:
    while(flag){ do something}
    in normal case, this could cause system busy and no responding because this program is only excuting the infinite while loop in module B, but my idea is that if push button again in module A,
    ---> flag = false, and module B would stop loop.

    Here I've to use while loop to reach my goal or is there any other way to get the same goal?

    I hope I make this problem clear , Thanks for your help much
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What do you mean by modules? Do you mean threads/processes, or something else?

    I'm not sure I understand why you want to loop in the first place. What I get is: you press a button in one program, the other program loops until you press the button again. Is that correct?

    Could you explain further, and post any other code you have. Also state your aim and project details.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Sorry for my bad English

    There are main.c (where windows created sending the flag to loop.c) and

    loop.c (where the loop is excuted according to
    Code:
    while(flag){do something}
    Now, in the main.c, it sends a message to loop.c that set flag to TRUE, and loop.c receives the message and start looping.

    Normally it willl cause the system busy because now it is a infinite loop, so I think there might be some ways like interrupt() to set flag to FALSE or multi-threads. If i am right, any more details about this, otherwise, some solutions??? THanks again!!
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Some options (in order of preference):

    1. Use a timer to perform the action in loop.c at every interval, say 10 times a second or whatever you need.

    2. Launch a second thread to run loop.c code.

    3. Pump the message loop from within the loop. Something like a DoEvents function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 11:44 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. difficult bitmap question
    By Mecnels in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2003, 07:03 AM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21