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

    Parallel programming

    Dear friends,

    Since I am a guy who recently migrated from PHP to desktop programming, I always think evrything should be linear...I mean when I write a code in PHP it just starts from line 1 and goes to the last line (I guess it does the same in old plain C maybe?)

    In PHP if you needed a running counter you could use JScript. But what about Visual C#?


    For example, I want in buttom of my form (my form does some basic things, so dont bother :P ) a counter be placed and as soon as user starts the program this counter starts runnig and counting real time, while the rest of program is doing as notmal.

    Another example. I want to embed a browser in my form, and I need it to be refreshed every few seconds while the user is working with other things in my form.

    I know it should be done with a loop (or not?) but if program enters the loop what will happen to the other functions of my program? are they should wait untill the loop is finished?

    Am I MAD or STUPID!!!!
    Last edited by Sean87; February 2nd, 2011 at 09:21 AM.

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Parallel programming

    C# is a pure object oriented programming language. PHP can be too, though some folks still cling to the 4.x C style that's short lived in the PHP world.

    no in C# there are a number of ways to accomplish the counter functionality, most common would be to use a "timer" object (a visual widget in the toolbox that you can drag & drop on to your form). it has an "event" called "elapsed" that you can handle or attach to, which basically create a method (function) that gets called by the timer object whenever the "elapsed" time come around. inside that elapsed callback / event handler you update a label on your form to let the user know that the timer has incremented, or however you do what you do (what you would normally do inside your "loop").

    windows are totally and completely non-linear. they are event based. they are cause and effect based. you have a control on the form that is interacted with by the user, which fires an "event" off, which you handle with an "event handler" (a method / function / bit of code in C#). that small portion will be the only linear. most of the time your program will be waiting on the user to do something with your app.

    the web browser / refresh works the same way. you embed a web browser control in your form, add a timer, handle the timer's elapsed event, and in that event handler, call the web browser control's refresh method.


    there's nothing "parallel" about any of this by the way. the title to this thread is misleading.
    Last edited by MadHatter; February 2nd, 2011 at 10:04 AM.

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Parallel programming

    MadHatter provided a lot of good information. The type of functionality you are looking for is called, in general, "event-driven programming". You can read about it generally at Wikipedia: http://en.wikipedia.org/wiki/Event-driven_programming

    To address your specific question more directly, a tutorial showing how to use a Timer (a form widget, as MadHatter mentioned)'s Tick() event to update a text box on a form. You should be to create a similar program that updates the time in a status bar (another sort of widget) along the bottom of your program. Link: http://www.java2s.com/Code/CSharp/GU...UIandtimer.htm

    Hope that helps!
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

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