Foros del Web » Programación para mayores de 30 ;) » C/C++ »

WaitForSingleObject

Estas en el tema de WaitForSingleObject en el foro de C/C++ en Foros del Web. Que alguien me ayude con WaitForSingleObject: Deseo hacer algo en el tiempo que WaitForSingleObject esta funcionando, po ejemplo ejecutar un ProgressBar pongo aqui todo el ...
  #1 (permalink)  
Antiguo 05/05/2011, 14:10
 
Fecha de Ingreso: abril-2011
Mensajes: 3
Antigüedad: 13 años, 1 mes
Puntos: 0
WaitForSingleObject

Que alguien me ayude con WaitForSingleObject:

Deseo hacer algo en el tiempo que WaitForSingleObject esta funcionando, po ejemplo ejecutar un ProgressBar pongo aqui todo el codigo para que me entiendan.

int Inventory::WinExecAndWait32(AnsiString FileName, int Visibility){
char zAppName[512];
char zCurDir[255];
AnsiString WorkDir;
TStartupInfo StartupInfo;
TProcessInformation ProcessInfo;

strcpy(zAppName, FileName.c_str());
WorkDir = GetCurrentDir();
strcpy(zCurDir, WorkDir.c_str());
setmem(&StartupInfo, sizeof(StartupInfo), 0);

StartupInfo.cb = sizeof(StartupInfo);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = Visibility;

if (!CreateProcess(NULL, zAppName, // pointer to command line string
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
false, // handle inheritance flag
CREATE_NEW_CONSOLE | // creation flags
NORMAL_PRIORITY_CLASS,
NULL, // pointer to new environment block
NULL, // pointer to current directory name
&StartupInfo, // pointer to STARTUPINFO
&ProcessInfo))
{
return -1; // pointer to PROCESS_INF
}else{
// Aqui esta el tema, el programa espera hasta que termine el proceso, pero yo en ese tiempo quiero ejecutar algo.
WaitForSingleObject(ProcessInfo.hProcess,INFINITE) ;

DWORD ExitCode;
GetExitCodeProcess(ProcessInfo.hProcess, &ExitCode);
return ExitCode;
}
}


No se si esta funcion la puedo meter en el while

Help me
  #2 (permalink)  
Antiguo 06/05/2011, 08:23
Avatar de sephirot47  
Fecha de Ingreso: marzo-2011
Ubicación: BCN
Mensajes: 54
Antigüedad: 13 años, 2 meses
Puntos: 9
Respuesta: WaitForSingleObject

Prueba a utilizar threads.
__________________
Todo lo que tiene un inicio tiene un final inevitable...

¡ No olvides darme karma si te fui útil ^^ !
  #3 (permalink)  
Antiguo 06/05/2011, 09:26
 
Fecha de Ingreso: abril-2011
Mensajes: 3
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: WaitForSingleObject

Bueno para lo que queria, ya lo he resuelto de forma un poco dudosa pero bueno, aqui va el codigo para que vean, he sustituido la primera funcion por esta
Código C++:
Ver original
  1. void ExternAPP::ExecuteInventoryEXE(){
  2.    if(this->ExistInventoryEXE()){
  3.      ShellExecute(NULL,"open",this->path.c_str(),this->parameters.c_str(),"",SW_SHOWNORMAL);
  4.    }
  5. }


Y en la forma lo que queria era, que al mismo tiempo que se ejecutaba lo que tengo en this->path.c_str() que fuera pasando un ProgessBar para saber cuando empesó y cuando terminó, pero me he cansado de tanto control y miren lo que he hecho en el OnClick de la forma.


Código C++:
Ver original
  1. void __fastcall TForm1::Button1Click(TObject *Sender)
  2. {
  3.      ProgressBar1->Position = 0;
  4.      Image1->Visible = false;
  5.      Image2->Visible = false;
  6.      Image3->Visible = false;
  7.      Image4->Visible = false;
  8.      Timer1->Enabled = true;
  9. }

Y en el Timer lo he hecho todo


Código C++:
Ver original
  1. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  2. {
  3.   if(ProgressBar1->Position != 20) Button2->Enabled = false;
  4.   if(ProgressBar1->Position == 2){
  5.    Image1->Visible = true;
  6.    hPtr->ExecuteGpupdateEXE();
  7.   }
  8.   if(ProgressBar1->Position == 8){
  9.    Image2->Visible = true;
  10.    hPtr->ExecuteWuaucltEXE();
  11.   }
  12.   if(ProgressBar1->Position == 16){
  13.    if(hPtr->ExistInventoryEXE()){
  14.      hPtr->ExecuteInventoryEXE();
  15.      Image3->Visible = true;
  16.    }else if(hPtr->ExistInventoryINSTALL()){
  17.      hPtr->ExecuteInventoryINSTALL();
  18.      Image4->Visible = true;
  19.  
  20.    }
  21.    ProgressBar1->Position = 20;
  22.    Button2->Enabled = true;
  23.   }
  24.   ProgressBar1->StepBy(2);
  25. }

Etiquetas: adf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 18:02.