Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Pages: 1
Cela peut intéresser qq'un …
open(w_multi)
et les fichiers à importer
w_multi.srw
$PBExportHeader$w_multi.srw forward global type w_multi from window end type type st_2 from statictext within w_multi end type type st_1 from statictext within w_multi end type type cb_stop2 from commandbutton within w_multi end type type cb_go2 from commandbutton within w_multi end type type cb_go1 from commandbutton within w_multi end type type cb_stop1 from commandbutton within w_multi end type type cb_close from commandbutton within w_multi end type end forward global type w_multi from window integer x = 1056 integer y = 496 integer width = 2144 integer height = 320 boolean titlebar = true string title = "Multi Tread API" boolean controlmenu = true windowtype windowtype = response! long backcolor = 79741120 event ue_cmp1 ( ) event ue_cmp2 ( ) event ue_refresh ( ) st_2 st_2 st_1 st_1 cb_stop2 cb_stop2 cb_go2 cb_go2 cb_go1 cb_go1 cb_stop1 cb_stop1 cb_close cb_close end type global w_multi w_multi type variables u_nvo_compteur cmp1 u_nvo_compteur cmp2 end variables event ue_cmp1; //st_1.Text = string(cmp1.ii_val_compteur) MessageBox("info","ue_cmp1()") end event event ue_refresh; st_1.Text = string(cmp1.ii_val_compteur) st_2.Text = string(cmp2.ii_val_compteur) end event on w_multi.create this.st_2=create st_2 this.st_1=create st_1 this.cb_stop2=create cb_stop2 this.cb_go2=create cb_go2 this.cb_go1=create cb_go1 this.cb_stop1=create cb_stop1 this.cb_close=create cb_close this.Control[]={this.st_2,& this.st_1,& this.cb_stop2,& this.cb_go2,& this.cb_go1,& this.cb_stop1,& this.cb_close} end on on w_multi.destroy destroy(this.st_2) destroy(this.st_1) destroy(this.cb_stop2) destroy(this.cb_go2) destroy(this.cb_go1) destroy(this.cb_stop1) destroy(this.cb_close) end on event open;errorreturn retour1,retour2,retour3,retour4 retour1 = SharedObjectRegister("u_nvo_compteur","i_cmp1") retour3 = SharedObjectGet ( "i_cmp1" , cmp1 ) retour2 = SharedObjectRegister("u_nvo_compteur","i_cmp2") retour4 = SharedObjectGet ( "i_cmp2" , cmp2 ) IF retour1 <> Success! OR retour2 <> Success! THEN MessageBox("Erreur !","SharedObjectRegister error",stopsign!) END IF IF retour3 <> Success! OR retour4 <> Success! THEN MessageBox("Erreur !","SharedObjectGet error",stopsign!) END IF Timer(0.05) end event event timer; this.EVENT TRIGGER ue_refresh() //MessageBox("info","Timer") end event type st_2 from statictext within w_multi integer x = 59 integer y = 140 integer width = 910 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 33554431 boolean enabled = false boolean focusrectangle = false end type type st_1 from statictext within w_multi integer x = 59 integer y = 44 integer width = 919 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 33554431 boolean enabled = false boolean focusrectangle = false end type type cb_stop2 from commandbutton within w_multi integer x = 1221 integer y = 128 integer width = 192 integer height = 84 integer taborder = 50 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "Stop" end type event clicked; cmp2.EVENT TRIGGER ue_stop() end event type cb_go2 from commandbutton within w_multi integer x = 1001 integer y = 128 integer width = 192 integer height = 84 integer taborder = 40 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "Go" end type event clicked; cmp2.EVENT TRIGGER ue_go() end event type cb_go1 from commandbutton within w_multi integer x = 997 integer y = 32 integer width = 192 integer height = 84 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "Go" end type event clicked; cmp1.EVENT TRIGGER ue_go() end event type cb_stop1 from commandbutton within w_multi integer x = 1221 integer y = 32 integer width = 192 integer height = 84 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "Stop" end type event clicked; cmp1.EVENT TRIGGER ue_stop() end event type cb_close from commandbutton within w_multi integer x = 1440 integer y = 32 integer width = 238 integer height = 84 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "&Close" end type event clicked; close(parent) end event
u_nvo_compteur.sru
$PBExportHeader$u_nvo_compteur.sru $PBExportComments$multi tache assync forward global type u_nvo_compteur from nonvisualobject end type end forward global type u_nvo_compteur from nonvisualobject event ue_go ( ) event ue_stop ( ) event ue_inc ( ) end type global u_nvo_compteur u_nvo_compteur type variables long ii_val_compteur boolean ib_isgoing end variables event ue_go; // flag compteur sur actif ib_isgoing = TRUE // départ dans le process this.EVENT POST ue_inc() end event event ue_stop; // flag compteur sur inactif ... ib_isgoing = FAlSE end event event ue_inc; // si compteur actif .... IF ib_isgoing = TRUE THEN // on inc le compteur.. ii_val_compteur++ // relance evt.... // les evt sont post pour permettre // le controle avec des evt TRIGGER this.EVENT POST ue_inc() //my_window.DYNAMIC EVENT TRIGGER ue_refresh() END IF end event on u_nvo_compteur.create TriggerEvent( this, "constructor" ) end on on u_nvo_compteur.destroy TriggerEvent( this, "destructor" ) end on
Hors ligne
Bonjour, merci pour cet exemple très intéressant.
J'ai essayé cet exemple, ça marche à merveille. Par contre, j'ai essayé d'introduire une requête SQL dans la fonction du Timer (Embedded SQL) et là, le programme ne tourne plus.
En fait, j'essaie d'utiliser le multithreading afin d'exécuter en parallèle des requêtes / des porcédures stockées assez lourdes.
Les Shared Object fonctionnent uniquement s'il n'y a pas d'accès à la base, ce qui reste insuffisant.
J'ai repris cet exemple en essayant de :
- exécuter de l'Embedded SQL.
- exécuter une procédure stockée.
- effectuer un retrieve sur une datawindow
Mais ça n'a pas abouti.
Pour info, je travaille avec PB10.5 et Oracle 10g en utilisant une connection ODBC.
J'ai essayé d'ajouter une nouvelle connection asynchrone qui sera chargée d'effectuer les accès à la base dans les Shared Object, toujours rien.
Est ce quelqu'un pourrait m'aider à accéder à la base à partir du timer "u_nvo_compteur.sru" ?
Merci d'avance.
Dernière modification par Amine (23-04-2012 08:43:53)
Hors ligne
Bonjour,
un thread s’exécute dans son propre contexte. Si tu veux exécuter des requêtes ou autres, tu dois procéder à une nouvelle connexion à la base de données à l'intérieur du thread.
Les transactions créées dans le contexte global de ton application ne sont pas disponibles dans le thread.
Hors ligne
Pages: 1