HOW TO SHOW: Processing...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    HOW TO SHOW: Processing...

    There are some textboxes placed on a form along with one button.When the user presses the button a modal window pops up till the work is finished and that window shows that circling processing GIF image.
    By showing the form as modal , the user will not be able to press the button again untill the shown modal window is closed, which happens automatically when the processing is done.
    This I tried to achieve this effect by creating the button's click event as follows:

    Futile attempt 1
    {
    OneForm oneform = new OneForm();
    oneform.Show();// mod-less form


    Thread.Sleep(); //Emulate work.Coz the Thread sleeps, the GIF icon can not animate

    oneform.Close() ;
    }

    Futile attempt 2
    {
    OneForm oneform = new OneForm();
    oneform.ShowDia log();// modal form


    Thread.Sleep(); //Emulate work.GIF will animate but this line will never execute untill I close the modal form ! USELESS

    }

    Futile attempt 3
    OneForm onefrm = new OneForm(); //oneform is a field so that I can access it from all methods
    {
    Thread th = new Thread(HeavyWor k);
    th.Start();
    oneform.ShowDia log();//main thread stops here untill I close it but I satrted another thread to execute my work, thank God
    }

    void HeavyWork()
    {
    Thread.Sleep(10 000);
    onefrm.Close(); //OOps this is created in GUI thread so cant access/close it from any other thread
    }


    Futile attempt 4 //I used this coz it was doing my work, well...almost
    {
    Thread th = new Thread(SHowForm );
    th.Start();


    Thread.Sleep(10 000);

    th.Abort(); //work done not close the form by ending the thread
    }

    void ShowForm()
    {
    new OneForm().ShowD ialog();
    }

    Now what happens is that the OneForm does not disappear untill I move the mouse on it.Even the dialog boxes are coming under it and when I move the mouse, it closes.

    How to solve this ?

    Thanks !
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Why does the thread need to sleep? Try a loop that checks whether or not your form should close with the animation in it. Put an Application.DoE vents() in that loop if you need other things to respond.

    Better yet, put a timer in your form that checks when the form should close and handles it then. I'm guessing the thread.sleep is blocking everything else from happening... though I thought animated gifs took care of themselves. To be honest, this is all speculation, I've never done it before. But experiment about and let us know :)

    Comment

    • akshaycjoshi
      New Member
      • Jan 2007
      • 153

      #3
      Thread.Sleep() emulates some actual work.
      Anyways I have found the answer.
      Here is the code

      Code:
      WaitForm waitfrm = new WaitForm();
      delegate void del();
      void CLOSE()
      {
      waitfrm.Close();<br/>}
      private void button1_Click(object sender, EventArgs e)
      {
      Thread th = new Thread(FUNC);
      th.Start();
      waitfrm = new WaitForm();
      waitfrm.ShowDialog();
      }
      void FUNC()
      {
      Thread.Sleep(10000);
      this.Invoke(new del(CLOSE));
      }

      Comment

      • amin531
        New Member
        • Sep 2009
        • 2

        #4
        if you know your form is in center of screen, you can use this comic code:
        int x = Cursor.Position .X;
        int y = Cursor.Position .Y;
        Cursor.Position = new Point(Screen.Pr imaryScreen.Wor kingArea.Width / 2, Screen.PrimaryS creen.WorkingAr ea.Height / 2);
        Cursor.Position = new Point(x, y);

        Comment

        • akshaycjoshi
          New Member
          • Jan 2007
          • 153

          #5
          What's that for ?
          :)

          Comment

          • amin531
            New Member
            • Sep 2009
            • 2

            #6
            i had the same problem, when stopping thread the form is showing until move mouse over.
            i solved it with this code after "thread.abort() ", programmaticall y move mouse on it and move to the old position again. it's not sensible for user because speed is very high.

            Comment

            • akshaycjoshi
              New Member
              • Jan 2007
              • 153

              #7
              hahahaha :)
              Thanks !

              Comment

              Working...