Visual C++ Multi-Threading (Please please HELP)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Visual C++ Multi-Threading (Please please HELP)

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    19

    Visual C++ Multi-Threading (Please please HELP)

    Hello All,
    I am not an expert in C++ programmer, but I have done some simple programming before. I would really appreciate some help.

    I have written a .NET program, using Windows form Application.
    My application is fairly simple.
    Basically, I have two simple buttons on my form.
    When the form is first loaded, I set up a global variable (bool run = true).

    And my first button is essentially a very simple while loop.

    while(run)
    {
    // do some code
    }

    And what I want to do, is have the second button set the value of the boolean to false (bool run = false).

    But, once I clicked the first button, I cannot even touch the second button!

    I have read quite about this, and I think my solution is to use a multi-threading.
    I have found some example codes on line for multi-threading, and I tried to incorporate those, but I don't know why I cannot get it to work. Once I click button #1, there is no way for me to be able to click button #2.

    I would really appreciate some help.

    Thanks,
    --Rudy

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: Visual C++ Multi-Threading (Please please HELP)

    Quote Originally Posted by rudy01 View Post
    But, once I clicked the first button, I cannot even touch the second button!
    That's because your program is not multithreaded. Once you start your infinite loop, it blocks your program's primary thread that is responsible for handling window messages like button clicks, so it can't do that anymore and becomes irresponsive.

    Multithreading could be useful as a fix here, but multithreading is an advanced topic and beginners better should start with something simpler. You should explain on a higher level what you want your program to do, so maybe we can find a solution that's simpler than multithreading. In case it's actually meant as a practicing example in multithreading, perhaps pick a simpler example/topic.

    Finaly, this is the wrong forum section for Windows Forms questions here. There's a specific one on C++/CLI including Windows Forms: http://forums.codeguru.com/forumdisp...ed-C-and-C-CLI Your question doesn't seem to be one that can be solved within just a few sentences, so please repost there.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Aug 2011
    Posts
    19

    Re: Visual C++ Multi-Threading (Please please HELP)

    All right,
    Thanks. I will post my question there under the same Thread, but explain the simpler form of what I want to do.

    --Rudy

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center