"C#" Back from Application.Run to place where was is called

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wael20
    New Member
    • Jul 2008
    • 6

    "C#" Back from Application.Run to place where was is called

    Hello,

    C# !!!
    How can i back from Application.Run to place where was is called?

    or, what should i do, when i must to use Application.Run ( new MyMainForm() ) to run my application?
    so i can´t use this way:

    MyMainForm myForm = new MyMainForm();
    myForm.ShowDial og();

    Thanks
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    So make a dummy Form that does the .ShowDialog() code and never actually shows itself.?

    Comment

    • wael20
      New Member
      • Jul 2008
      • 6

      #3
      I need the GUI, that i started, to test it with NUnitforms...

      so...
      How can i back from Application.Run to place where was is called? (to test it with NUnitforms)

      or, what should i do, when i must to use Application.Run ( new MyMainForm() ) to run my application?
      so i can´t use this way:

      MyMainForm myForm = new MyMainForm();
      myForm.ShowDial og();

      because my application use Backgroundworke r.

      I tried it like this, but i couldn't debug it:
      .....
      ApplicationTest Start _applicationTes tStart = new ApplicationTest Start();
      ThreadStart ts = new ThreadStart(_ap plicationTestSt art.Run);
      Thread t1 = new Thread(ts);
      t1.Start();
      --------------------------------------------------------------------------------
      public class ApplicationTest Start
      {
      public ApplicationTest Start()
      {
      }

      public void Run()
      {
      Application.Ena bleVisualStyles ();
      Application.Set CompatibleTextR enderingDefault (false);
      Application.Run (new MyApplicationCo ntext(new string[] {}));
      }
      }

      Thanks

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        What are you trying to do? The structure isn't too clear.
        You can do this, if it helps:
        [code=c#]
        TestForm tm = new TestForm;
        Application.Run (tm);
        [/code]

        Comment

        • wael20
          New Member
          • Jul 2008
          • 6

          #5
          Just for example:
          [PHP]
          public class ProgramTEST
          {
          public ProgramTEST()
          {
          Application.Ena bleVisualStyles ();
          Application.Set CompatibleTextR enderingDefault (false);
          Application.Run (new MyApplicationCo ntext(new string[] {})); // -->This bolcks the course of the application.
          }

          public ControlTester buttonTester;

          public void Test()
          {
          buttonTester = new ControlTester(" _okButton", "myForm");

          buttonTester.Fi reEvent("Click" );
          }
          }[/PHP]

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            I don't know what's going on in your Test() function, but the rest looks fine?

            Comment

            • wael20
              New Member
              • Jul 2008
              • 6

              #7
              It is just example, a GUI will opened and than will clicked on OK button automatically

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                So why not have the code that "clicks" the button automatically happen in the gui, like in the form_load() event handler?

                Comment

                • wael20
                  New Member
                  • Jul 2008
                  • 6

                  #9
                  I cannot change anything on the GUI Software, It is Just example, that i click on this button, the problem is:

                  On this following line, my program stops:.

                  Application.Run (new MyApplicationCo ntext(new string[] {}));

                  or, when you write:

                  ProgramTEST MyTest = new ProgramTEST(); // here my program stops, tell i close the GUI!!!But i need the GUI!
                  MyTest.Test();

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    HAve you tried making a new thread?

                    Comment

                    • wael20
                      New Member
                      • Jul 2008
                      • 6

                      #11
                      I started my GUI in Thread, but i cannot debug it!

                      Code:
                      public ProgramTEST()
                      {
                                ApplicationTestStart _applicationTestStart = new ApplicationTestStart();
                                ThreadStart ts2 = new ThreadStart(_applicationTestStart.Run);
                                Thread t1 = new Thread(ts2);
                                t1.Start();
                      }
                      --------------------------------------------------------------------------
                      Code:
                      public ApplicationTestStart()
                      {
                      }
                      public void Run()
                      {
                                Application.EnableVisualStyles();
                                Application.SetCompatibleTextRenderingDefault(false);
                                Application.Run(new BootApplicationContext(new string[] { }));
                      }
                      do you know, how i can use "BeginInvok e" make it work?

                      Comment

                      Working...