Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Application.Run()???

Application.Run()???

Scheduled Pinned Locked Moved C#
question
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gjm
    wrote on last edited by
    #1

    What is Application.Run(); What is its real use? I have read the msdn but I couldn't understand. Please give me a different and easy answer

    L P D 3 Replies Last reply
    0
    • G Gjm

      What is Application.Run(); What is its real use? I have read the msdn but I couldn't understand. Please give me a different and easy answer

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Application.Run(form) shows the form, runs a message pump, and waits until the form gets closed. it exists in the Main() method of most WinForm applications. I've never used Application.Run() without form. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      1 Reply Last reply
      0
      • G Gjm

        What is Application.Run(); What is its real use? I have read the msdn but I couldn't understand. Please give me a different and easy answer

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I'm guessing it tells an Application to Run, but some context might be helpful. :-D

        L B 2 Replies Last reply
        0
        • P PIEBALDconsult

          I'm guessing it tells an Application to Run, but some context might be helpful. :-D

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Some context? :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          P 1 Reply Last reply
          0
          • P PIEBALDconsult

            I'm guessing it tells an Application to Run, but some context might be helpful. :-D

            B Offline
            B Offline
            binhvtt
            wrote on last edited by
            #5

            You can ref these link: what does this method for : http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run(VS.71).aspx[^] And what's message loop in window: http://www.winprog.org/tutorial/message_loop.html[^] -Binh

            P 1 Reply Last reply
            0
            • L Luc Pattyn

              Some context? :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I'll wait for the OP to give context; it could be some wacky WidgetCo.Application.Run.

              L 1 Reply Last reply
              0
              • P PIEBALDconsult

                I'll wait for the OP to give context; it could be some wacky WidgetCo.Application.Run.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                You're not the adventurous type then? ;P

                Luc Pattyn [Forum Guidelines] [My Articles]


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                P 1 Reply Last reply
                0
                • L Luc Pattyn

                  You're not the adventurous type then? ;P

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Jumping to conclusions doesn't pay.

                  1 Reply Last reply
                  0
                  • B binhvtt

                    You can ref these link: what does this method for : http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run(VS.71).aspx[^] And what's message loop in window: http://www.winprog.org/tutorial/message_loop.html[^] -Binh

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    How do you know that's what the OP means?

                    B 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      How do you know that's what the OP means?

                      B Offline
                      B Offline
                      binhvtt
                      wrote on last edited by
                      #10

                      In which part ?

                      P 1 Reply Last reply
                      0
                      • B binhvtt

                        In which part ?

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #11

                        All of it.

                        1 Reply Last reply
                        0
                        • G Gjm

                          What is Application.Run(); What is its real use? I have read the msdn but I couldn't understand. Please give me a different and easy answer

                          D Offline
                          D Offline
                          dojohansen
                          wrote on last edited by
                          #12

                          Windows is basically a message-driven system. Unlike the programming model we get to play with, where we "receive events" when they occur, each application actually has to make system calls to get messages for the application from the system. These messages are generated by the OS and/or other programs and represent information such as a key changing state from up to down, the mouse moving, the program needs to redraw itself, and a gazillion other things. So crudely put, and surely leaving out lots of detail, the Run() method displays the form passed to it, implements a loop that calls the Windows GetMessage() function and processes the messages in the queue. Messages received will be passed to relevant controls and the controls in turn raise events, providing us with a way of plugging our custom code into this loop. When the application receives a WM_CLOSE message or the form closes, the loop terminates and the Main method returns, terminating the program. This is also why normal Windows Forms apps are terrible for implementing things like games. The GetMessage() function blocks when the message queue for an application is empty, which is very good when the application *is* event-driven and doesn't need to do anything other than in response to some external event - because it let's Windows allocate CPU to other programs that do have something in their message queue. Games however need to keep working and drawing and calculating object movements and so on even if there are no external events. They therefore implement the message loop a little differently, calling the system function PeekMessage() instead, which never blocks but returns immediately even if there are no messages. That's great for games, but it also explains why games are so unfriendly multi-taskers - they always take a lot of resources. A digression if I may: Unfortunately this does make some seemingly simple things a bit tricky to implement in Windows Forms apps. For example, let's say you want to do something *while* a mouse button is pressed, as opposed to in response to the transition from up to down or down to up. You could do this with a timer (which is a WM_TIMER message - the lowest-priority message of all Windows Messages), but it wouldn't be very nice. You might have to start another thread doing the work when the button is pressed and cause it to stop when the button is released, but that's a bit complicated too, because the controls are not thread-safe so this other thread can't update anything in the UI, but instead has to marsh

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups