CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2002
    Posts
    87

    Simple Threading Question

    Dear Gurus,

    I am running some lengthy calculations and attempt to provide some feedback from it in the dialog via showing the iteration number, elapsed time, etc, my "calculation" program looks like this:

    void CalcProgram()
    {
    ...
    Thread MyProgress = new Thread(new ThreadStart(MyUpdate));
    // Start the thread
    MyProgress.Start();

    for(i=0; i<IterationNumber; i++)
    {
    ...// Long calcuations
    ...
    MessageBox.Show("I am here");
    }

    }

    When I run the program and comment out the MessageBox shown, the thread seem to be not working, i.e. it does not provide the expected output. However, when the message box is there, the thread seem to be working as expected only when the box is shown, when I click "OK" on the box it does not provide any updates until the MessageBox is shown again.

    Does anybody knows why????

    Thank you.

  2. #2
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Simple Threading Question

    I'm far from being an "guru" on threads, but have you considered using a BackgroundWorker class instead?
    Basically it is a thread with some extra functionality that might help you out.

    Here is some explanation and example: http://www.albahari.com/threading/part3.aspx

    If you want to report something else than just a percentage with the BackgroundWorker, you can use the UserState object parameter to pass just about anything you want and then cast it for your original data.

  3. #3
    Join Date
    May 2007
    Posts
    1,546

    Re: Simple Threading Question

    With no code we can't tell you what you've done wrong...
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

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

Featured