Quoi, tu ne connais pas PB ? Va falloir parcourir tout le forum alors !

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 21-06-2007 08:04:09

JCZ  
Builder Power
Award: bf
Lieu: 75019 paris
Date d'inscription: 21-05-2007
Messages: 1724
Pépites: 496,453,703,213
Banque: 9,223,372,036,854,776,000

[SOURCE] Exemple de multi-thread

Cela peut intéresser qq'un …

Code: pb

open(w_multi)


et les fichiers à importer

w_multi.srw

Code: pb

$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

Code: pb

$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


Face à l'agression, la puissance de l'intelligence

Hors ligne

 

#2 21-06-2007 08:07:43

pick ouic  
La bourse ou la vie ^^
Award: gearotter
Lieu: Massy-Verrières
Date d'inscription: 29-05-2006
Messages: 4658
Pépites: 942
Banque: 2,147,483,647
Site web

Re: [SOURCE] Exemple de multi-thread

50 à ton compteur de pépitos.


Connaitre son ignorance est une grande part de la connaissance.
http://animegifs.free.fr/anime/mazinger/mazinger.gif

Hors ligne

 

#3 23-04-2012 08:42:57

Amine  
Membre Geek
Date d'inscription: 20-04-2012
Messages: 20
Pépites: 81
Banque: 0

Re: [SOURCE] Exemple de multi-thread

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)


http://www.gameslist.com/downloadgames/Microcosmic-Shooter/68x42.jpgLe plus de foutaises que tu peux supporter, le plus de foutaises tu vas entendre

Hors ligne

 

#4 23-04-2012 08:57:25

buck  
Modérateur
Lieu: Dijon
Date d'inscription: 31-07-2008
Messages: 747
Pépites: 1,028,843
Banque: 171,170,849,654

Re: [SOURCE] Exemple de multi-thread

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

 

Pied de page des forums

Propulsé par FluxBB 1.2.22