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. Managed C++/CLI
  4. Form refresh... and accept click on button while performing other task...

Form refresh... and accept click on button while performing other task...

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelpcareer
6 Posts 3 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.
  • T Offline
    T Offline
    Thilek
    wrote on last edited by
    #1

    hi guys, i am having program when i minimize then maximize a form that running a job.. My program will scan for worms in the selected directories.. when i click start it will start scanning .... while scanning it will add the scanned file names into a listbox.... if i minimize the form or open anothe windows or application (lets say my document)then click back on the form , its not showing the contents on the list box.. the list box is empty till the whole scanning process is completed... How can i make it show the list (refresh) even after i minimize it and show it back.... and my second question is how i can allow the form to accept click on others buttons while its still scanning.. this is to allow me to stop a the scanning.... if i click on close it waits till the scanning to complete before it close... Kindly help me...

    N E 2 Replies Last reply
    0
    • T Thilek

      hi guys, i am having program when i minimize then maximize a form that running a job.. My program will scan for worms in the selected directories.. when i click start it will start scanning .... while scanning it will add the scanned file names into a listbox.... if i minimize the form or open anothe windows or application (lets say my document)then click back on the form , its not showing the contents on the list box.. the list box is empty till the whole scanning process is completed... How can i make it show the list (refresh) even after i minimize it and show it back.... and my second question is how i can allow the form to accept click on others buttons while its still scanning.. this is to allow me to stop a the scanning.... if i click on close it waits till the scanning to complete before it close... Kindly help me...

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Run the scanning in a separate thread. It will solve your two problems. :)

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • T Thilek

        hi guys, i am having program when i minimize then maximize a form that running a job.. My program will scan for worms in the selected directories.. when i click start it will start scanning .... while scanning it will add the scanned file names into a listbox.... if i minimize the form or open anothe windows or application (lets say my document)then click back on the form , its not showing the contents on the list box.. the list box is empty till the whole scanning process is completed... How can i make it show the list (refresh) even after i minimize it and show it back.... and my second question is how i can allow the form to accept click on others buttons while its still scanning.. this is to allow me to stop a the scanning.... if i click on close it waits till the scanning to complete before it close... Kindly help me...

        E Offline
        E Offline
        erfi
        wrote on last edited by
        #3

        yes. if your program works in a loop, the only whey to keep your UI alive is to use the Thread. write youre loop in a function and then run it on a thread.

        sometimes 0 can be 1

        T 1 Reply Last reply
        0
        • E erfi

          yes. if your program works in a loop, the only whey to keep your UI alive is to use the Thread. write youre loop in a function and then run it on a thread.

          sometimes 0 can be 1

          T Offline
          T Offline
          Thilek
          wrote on last edited by
          #4

          how to run on threat i am new to this.. kindly gv me some example plz...

          T 1 Reply Last reply
          0
          • T Thilek

            how to run on threat i am new to this.. kindly gv me some example plz...

            T Offline
            T Offline
            Thilek
            wrote on last edited by
            #5

            Below is my coding.. i not sure where to put the thread....

            #pragma once

            #include "QUARANTINE.h"

            using namespace System;
            using namespace System::ComponentModel;
            using namespace System::Collections;
            using namespace System::Windows::Forms;
            using namespace System::Data;
            using namespace System::Drawing;

            namespace Enhan_GUI {

            /// <summary>
            /// Summary for manscan
            ///
            /// WARNING: If you change the name of this class, you will need to change the
            ///          'Resource File Name' property for the managed resource compiler tool
            ///          associated with all .resx files this class depends on.  Otherwise,
            ///          the designers will not be able to interact properly with localized
            ///          resources associated with this form.
            /// </summary>
            public ref class manscan : public System::Windows::Forms::Form
            {
            public:
            	manscan(void)
            	{
            		InitializeComponent();
            		//
            		//TODO: Add the constructor code here
            		//
            	}
            
            protected:
            	/// <summary>
            	/// Clean up any resources being used.
            	/// </summary>
            	~manscan()
            	{
            		if (components)
            		{
            			delete components;
            		}
            	}
            private: System::Windows::Forms::PictureBox^  pictureBox1;
            protected: 
            private: System::Windows::Forms::GroupBox^  gbxfunction;
            private: System::Windows::Forms::Button^  cmdPause;
            private: System::Windows::Forms::Button^  cmdStart;
            private: System::Windows::Forms::Label^  label2;
            private: System::Windows::Forms::Button^  cmdClose;
            private: System::Windows::Forms::Label^  label1;
            private: System::Windows::Forms::Label^  label3;
            
            private:
            	/// <summary>
            	/// Required designer variable.
            	/// </summary>
            	System::ComponentModel::Container ^components;
            

            #pragma region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            void InitializeComponent(void)
            {
            System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(manscan::typeid));
            this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
            this->gbxfunction = (gcnew System::Windows::Forms::GroupBox());
            this->cmdPause = (gcnew System::Windows::Forms::Button());
            this->cmdStart = (gcnew System::Windows::Forms::Button());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->cmdClose = (gcnew System::Window

            E 1 Reply Last reply
            0
            • T Thilek

              Below is my coding.. i not sure where to put the thread....

              #pragma once

              #include "QUARANTINE.h"

              using namespace System;
              using namespace System::ComponentModel;
              using namespace System::Collections;
              using namespace System::Windows::Forms;
              using namespace System::Data;
              using namespace System::Drawing;

              namespace Enhan_GUI {

              /// <summary>
              /// Summary for manscan
              ///
              /// WARNING: If you change the name of this class, you will need to change the
              ///          'Resource File Name' property for the managed resource compiler tool
              ///          associated with all .resx files this class depends on.  Otherwise,
              ///          the designers will not be able to interact properly with localized
              ///          resources associated with this form.
              /// </summary>
              public ref class manscan : public System::Windows::Forms::Form
              {
              public:
              	manscan(void)
              	{
              		InitializeComponent();
              		//
              		//TODO: Add the constructor code here
              		//
              	}
              
              protected:
              	/// <summary>
              	/// Clean up any resources being used.
              	/// </summary>
              	~manscan()
              	{
              		if (components)
              		{
              			delete components;
              		}
              	}
              private: System::Windows::Forms::PictureBox^  pictureBox1;
              protected: 
              private: System::Windows::Forms::GroupBox^  gbxfunction;
              private: System::Windows::Forms::Button^  cmdPause;
              private: System::Windows::Forms::Button^  cmdStart;
              private: System::Windows::Forms::Label^  label2;
              private: System::Windows::Forms::Button^  cmdClose;
              private: System::Windows::Forms::Label^  label1;
              private: System::Windows::Forms::Label^  label3;
              
              private:
              	/// <summary>
              	/// Required designer variable.
              	/// </summary>
              	System::ComponentModel::Container ^components;
              

              #pragma region Windows Form Designer generated code
              /// <summary>
              /// Required method for Designer support - do not modify
              /// the contents of this method with the code editor.
              /// </summary>
              void InitializeComponent(void)
              {
              System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(manscan::typeid));
              this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
              this->gbxfunction = (gcnew System::Windows::Forms::GroupBox());
              this->cmdPause = (gcnew System::Windows::Forms::Button());
              this->cmdStart = (gcnew System::Windows::Forms::Button());
              this->label2 = (gcnew System::Windows::Forms::Label());
              this->cmdClose = (gcnew System::Window

              E Offline
              E Offline
              erfi
              wrote on last edited by
              #6

              your code is too long and i haven't enough time to read it all. but below is the way to use a thread: my form has two button named "buttonStart" and "buttonStop" when i press the first one my thread starts and when press the second one my thread stops. this is my code :

              private: Thread^ myThread;
              private: static volatile bool stop;

              private: System::Void buttonStart_Click(System::Object^ sender, System::EventArgs^ e) {
              myThread = gcnew Thread(gcnew ThreadStart( &Form1::Function ));
              stop = false;
              myThread->Start();
              buttonStart->Enabled = false;
              }
              private: System::Void buttonStop_Click(System::Object^ sender, System::EventArgs^ e) {
              stop = true;
              buttonStart->Enabled = true;
              }
              public: static void Function()
              {
              MessageBox::Show("thread is now starting");
              // for example a "do while" loop
              do
              {
              // do some work
              }
              while(stop == false);
              MessageBox::Show("thread stoped");
              }

              you can add some extra controls to your form and see that when you press the start button your controls will be alive. my function has a infinite loop and if you run it without threads your UI hangs. however, i suggest you to read these: Thread Class[^] Threading tutorial[^] to get a clean understanding of threads. and there are many perfect articles of threading in CP[^]: 1 2 3 4 5

              sometimes 0 can be 1

              modified on Wednesday, March 25, 2009 5:37 PM

              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