Form refresh... and accept click on button while performing other task...
-
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...
-
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...
Run the scanning in a separate thread. It will solve your two problems. :)
Navaneeth How to use google | Ask smart questions
-
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...
-
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
-
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 -
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::Windowyour 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