Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Timers.Au3]Wielowątkowosc Autoit


Rekomendowane odpowiedzi

Opublikowano

Timers.au3 jest dołączony do autoita na starcie, lecz jeżeli ktoś niema lub mu nie działa to podam source tej biblioteki.

 

#include-once

; #INDEX# =======================================================================================================================
; Title .........: Timers
; AutoIt Version : 3.2.3++
; Language ......: English
; Description ...: Functions that assist with Timers management.
;                  An application uses a timer to schedule an event for a window after a specified time has elapsed.
;                  Each time the specified interval (or time-out value) for a timer elapses, the system notifies the window
;                  associated with the timer. Because a timer's accuracy depends on the system clock rate and how often the
;                  application retrieves messages from the message queue, the time-out value is only approximate.
; Author(s) .....: Gary Frost
; Dll(s) ........: user32.dll, kernel32.dll
; ===============================================================================================================================

; #VARIABLES# ===================================================================================================================
Global $_Timers_aTimerIDs[1][3]
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_Timer_Diff
;_Timer_GetIdleTime
;_Timer_GetTimerID
;_Timer_Init
;_Timer_KillAllTimers
;_Timer_KillTimer
;_Timer_SetTimer
; ===============================================================================================================================

; #INTERNAL_USE_ONLY# ===========================================================================================================
;__Timer_QueryPerformanceCounter
;__Timer_QueryPerformanceFrequency
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_Diff
; Description ...: Returns the difference in time from a previous call to _Timer_Init
; Syntax.........: _Timer_Diff($iTimeStamp)
; Parameters ....: $iTimeStamp - Timestamp returned from a previous call to _Timer_Init().
; Return values .: Success - Returns the time difference (in milliseconds) from a previous call to _Timer_Init().
; Author ........: Gary Frost, original by Toady
; Modified.......:
; Remarks .......:
; Related .......: _Timer_Init
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_Diff($iTimeStamp)
Return 1000 * (__Timer_QueryPerformanceCounter() - $iTimeStamp) / __Timer_QueryPerformanceFrequency()
EndFunc   ;==>_Timer_Diff

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_GetIdleTime
; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse)
; Syntax.........: _Timer_GetIdleTime()
; Parameters ....: None
; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity
;                  Failure - Sets @extended = 1 if rollover occurs (see remarks)
; Author ........: PsaltyDS at http://www.autoitscript.com/forum
; Modified.......:
; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so,
;                  which makes it possible for last user activity to be before the rollover, but run time
;                  of this function to be after the rollover.  If this happens, @extended = 1 and the
;                  returned value is ticks since rollover occured.
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_GetIdleTime()
; Get ticks at last activity
Local $tStruct = DllStructCreate("uint;dword");
DllStructSetData($tStruct, 1, DllStructGetSize($tStruct));
Local $aResult = DllCall("user32.dll", "bool", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct))
If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, 0)

; Get current ticks since last restart
Local $avTicks = DllCall("Kernel32.dll", "dword", "GetTickCount")
If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0)

; Return time since last activity, in ticks (approx milliseconds)
Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2)
If $iDiff < 0 Then  Return SetExtended(1, $avTicks[0])    ; Rollover of ticks counter has occured
; Normal return
Return $iDiff
EndFunc   ;==>_Timer_GetIdleTime

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_GetTimerID
; Description ...: Returns the Timer ID from $iwParam
; Syntax.........: _Timer_GetTimerID($iwParam)
; Parameters ....: $iwParam - Specifies the timer identifier event.
; Return values .: Success - The Timer ID
;                  Failure - 0
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......: _Timer_SetTimer
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_GetTimerID($iwParam)
Local $_iTimerID = Dec(Hex($iwParam, 8)), $iMax = UBound($_Timers_aTimerIDs) - 1
For $x = 1 To $iMax
	If $_iTimerID = $_Timers_aTimerIDs[$x][1] Then Return $_Timers_aTimerIDs[$x][0]
Next
Return 0
EndFunc   ;==>_Timer_GetTimerID

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_Init
; Description ...: Returns a timestamp (in milliseconds).
; Syntax.........: _Timer_Init()
; Parameters ....:
; Return values .: Success - Returns a timestamp number (in milliseconds).
; Author ........: Gary Frost, original by Toady
; Modified.......:
; Remarks .......:
; Related .......: _Timer_Diff
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_Init()
Return __Timer_QueryPerformanceCounter()
EndFunc   ;==>_Timer_Init

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_KillAllTimers
; Description ...: Destroys all the timers
; Syntax.........: _Timer_KillAllTimers($hWnd)
; Parameters ....: $hWnd        - Handle to the window associated with the timers.
;                  |This value must be the same as the hWnd value passed to the _Timer_SetTimer function that created the timer
; Return values .: Success - True
;                  Failure - False
; Author ........: Gary Frost
; Modified.......: Squirrely1
; Remarks .......: The _Timer_KillAllTimers function does not remove WM_TIMER messages already posted to the message queue
; Related .......: _Timer_KillTimer, _Timer_SetTimer
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_KillAllTimers($hWnd)
Local $iNumTimers = $_Timers_aTimerIDs[0][0]
If $iNumTimers = 0 Then  Return False
Local $aResult, $hCallBack = 0
For $x = $iNumTimers To 1 Step -1
	If IsHWnd($hWnd) Then
		$aResult = DllCall("user32.dll", "bool", "KillTimer", "hwnd", $hWnd, "uint_ptr", $_Timers_aTimerIDs[$x][1])
	Else
		$aResult = DllCall("user32.dll", "bool", "KillTimer", "hwnd", $hWnd, "uint_ptr", $_Timers_aTimerIDs[$x][0])
	EndIf
	If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, False)
	$hCallBack = $_Timers_aTimerIDs[$x][2]
	If $hCallBack <> 0 Then DllCallbackFree($hCallBack)
	$_Timers_aTimerIDs[0][0] -= 1
Next
ReDim $_Timers_aTimerIDs[1][3]
Return True
EndFunc   ;==>_Timer_KillAllTimers

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_KillTimer
; Description ...: Destroys the specified timer
; Syntax.........: _Timer_KillTimer($hWnd, $iTimerID)
; Parameters ....: $hWnd        - Handle to the window associated with the specified timer.
;                  |This value must be the same as the hWnd value passed to the _Timer_SetTimer function that created the timer
;                  $iTimerID      - Specifies the timer to be destroyed
; Return values .: Success - True
;                  Failure - False
; Author ........: Gary Frost
; Modified.......: Squirrely1
; Remarks .......: The _Timer_KillTimer function does not remove WM_TIMER messages already posted to the message queue
; Related .......: _Timer_KillAllTimers, _Timer_SetTimer
; Link ..........: @@MsdnLink@@ KillTimer
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_KillTimer($hWnd, $iTimerID)
Local $aResult[1] = [0], $hCallBack = 0, $iUBound = UBound($_Timers_aTimerIDs) - 1
For $x = 1 To $iUBound
	If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
		If IsHWnd($hWnd) Then
			$aResult = DllCall("user32.dll", "bool", "KillTimer", "hwnd", $hWnd, "uint_ptr", $_Timers_aTimerIDs[$x][1])
		Else
			$aResult = DllCall("user32.dll", "bool", "KillTimer", "hwnd", $hWnd, "uint_ptr", $_Timers_aTimerIDs[$x][0])
		EndIf
		If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, False)
		$hCallBack = $_Timers_aTimerIDs[$x][2]
		If $hCallBack <> 0 Then DllCallbackFree($hCallBack)
		For $i = $x To $iUBound - 1
			$_Timers_aTimerIDs[$i][0] = $_Timers_aTimerIDs[$i + 1][0]
			$_Timers_aTimerIDs[$i][1] = $_Timers_aTimerIDs[$i + 1][1]
			$_Timers_aTimerIDs[$i][2] = $_Timers_aTimerIDs[$i + 1][2]
		Next
		ReDim $_Timers_aTimerIDs[uBound($_Timers_aTimerIDs - 1)][3]
		$_Timers_aTimerIDs[0][0] -= 1
		ExitLoop
	EndIf
Next
Return $aResult[0] <> 0
EndFunc   ;==>_Timer_KillTimer

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __Timer_QueryPerformanceCounter
; Description ...: Retrieves the current value of the high-resolution performance counter
; Syntax.........: __Timer_QueryPerformanceCounter()
; Parameters ....:
; Return values .: Success - Current performance-counter value, in counts
;                  Failure - -1
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......: __Timer_QueryPerformanceFrequency
; Link ..........: @@MsdnLink@@ QueryPerformanceCounter
; Example .......:
; ===============================================================================================================================
Func __Timer_QueryPerformanceCounter()
Local $aResult = DllCall("kernel32.dll", "bool", "QueryPerformanceCounter", "int64*", 0)
If @error Then Return SetError(@error, @extended, -1)
Return SetExtended($aResult[0], $aResult[1])
EndFunc   ;==>__Timer_QueryPerformanceCounter

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __Timer_QueryPerformanceFrequency
; Description ...: Retrieves the current value of the high-resolution performance counter
; Syntax.........: __Timer_QueryPerformanceFrequency()
; Parameters ....:
; Return values .: Success - Current performance-counter frequency, in counts per second
;                  Failure - 0
; Author ........: Gary Frost
; Modified.......:
; Remarks .......: If the installed hardware does not support a high-resolution performance counter, the return can be zero.
; Related .......: __Timer_QueryPerformanceCounter
; Link ..........: @@MsdnLink@@ QueryPerformanceCounter
; Example .......:
; ===============================================================================================================================
Func __Timer_QueryPerformanceFrequency()
Local $aResult = DllCall("kernel32.dll", "bool", "QueryPerformanceFrequency", "int64*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetExtended($aResult[0], $aResult[1])
EndFunc   ;==>__Timer_QueryPerformanceFrequency

; #FUNCTION# ====================================================================================================================
; Name...........: _Timer_SetTimer
; Description ...: Creates a timer with the specified time-out value
; Syntax.........: _Timer_SetTimer($hWnd[, $iElapse = 250[, $sTimerFunc = ""[, $iTimerID = -1]]])
; Parameters ....: $hWnd        - Handle to the window to be associated with the timer.
;                  |This window must be owned by the calling thread
;                  $iElapse     - Specifies the time-out value, in milliseconds
;                  $sTimerFunc  - Function name to be notified when the time-out value elapses
;                  $iTimerID    - Specifies a timer identifier.
;                  |If $iTimerID = -1 then a new timer is created
;                  |If $iTimerID matches an existing timer then the timer is replaced
;                  |If $iTimerID = -1 and $sTimerFunc = "" then timer will use WM_TIMER events
; Return values .: Success - Integer identifying the new timer
;                  Failure - 0
; Author ........: Gary Frost
; Modified.......: Squirrely1
; Remarks .......:
; Related .......: _Timer_KillTimer, _Timer_KillAllTimers, _Timer_GetTimerID
; Link ..........: @@MsdnLink@@ SetTimer
; Example .......: Yes
; ===============================================================================================================================
Func _Timer_SetTimer($hWnd, $iElapse = 250, $sTimerFunc = "", $iTimerID = -1)
Local $aResult[1] = [0], $pTimerFunc = 0, $hCallBack = 0, $iIndex = $_Timers_aTimerIDs[0][0] + 1
If $iTimerID = -1 Then ; create a new timer
	ReDim $_Timers_aTimerIDs[$iIndex + 1][3]
	$_Timers_aTimerIDs[0][0] = $iIndex
	$iTimerID = $iIndex + 1000
	For $x = 1 To $iIndex
		If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
			$iTimerID = $iTimerID + 1
			$x = 0
		EndIf
	Next
	If $sTimerFunc <> "" Then ; using callbacks, if $sTimerFunc = "" then using WM_TIMER events
		$hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;uint_ptr;dword")
		If $hCallBack = 0 Then Return SetError(-1, -1, 0)
		$pTimerFunc = DllCallbackGetPtr($hCallBack)
		If $pTimerFunc = 0 Then Return SetError(-1, -1, 0)
	EndIf
	$aResult = DllCall("user32.dll", "uint_ptr", "SetTimer", "hwnd", $hWnd, "uint_ptr", $iTimerID, "uint", $iElapse, "ptr", $pTimerFunc)
	If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, 0)
	$_Timers_aTimerIDs[$iIndex][0] = $aResult[0] ; integer identifier
	$_Timers_aTimerIDs[$iIndex][1] = $iTimerID ; timer id
	$_Timers_aTimerIDs[$iIndex][2] = $hCallBack ; callback identifier, need this for the Kill Timer
Else ; reuse timer
	For $x = 1 To $iIndex - 1
		If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
			If IsHWnd($hWnd) Then $iTimerID = $_Timers_aTimerIDs[$x][1]
			$hCallBack = $_Timers_aTimerIDs[$x][2]
			If $hCallBack <> 0 Then ; call back was used to create the timer
				$pTimerFunc = DllCallbackGetPtr($hCallBack)
				If $pTimerFunc = 0 Then Return SetError(-1, -1, 0)
			EndIf
			$aResult = DllCall("user32.dll", "uint_ptr", "SetTimer", "hwnd", $hWnd, "uint_ptr", $iTimerID, "int", $iElapse, "ptr", $pTimerFunc)
			If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, 0)
			ExitLoop
		EndIf
	Next
EndIf
Return $aResult[0]
EndFunc   ;==>_Timer_SetTimer

 

 

Ogólnie czym jest wielowątkowosc?

Wielowątkowośc to inaczej obsługiwanie wiecej niż jedna funkcja na raz. Autoit sam w sobie jest jedno wątkowy.

 

_Timer_SetTimer($hWnd [, $iElapse = 250 [, $sTimerFunc = "" [, $iTimerID = -1]]]); odpala daną funkcje i powtarza ją co okreslony czas dopuki się jej nie "zabije"

_Timer_KillTimer($hWnd, $iTimerID); usuwa dany timer(zabija funkcje)

_Timer_KillAllTimers($hWnd); usuwa wszystkie używane timery(zabija wszystkie funkcje)

_Timer_Diff($iTimeStamp); odczytuje wartosc z timera

_Timer_Init(); startuje timera(liczy czas od uzycia funkcji)

 

 

Nie polecam używac Sleep w tej funkcji ponieważ skrypt zaczyna zamulac.

Przykład użycia tych 3 funkcji

 

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 245, 151, 192, 124)
$Button1 = GUICtrlCreateButton("progressbar", 8, 8, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("KillTimer(czas)", 88, 8, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("KillAllTimers", 168, 8, 75, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Label1", 100, 40)
$Label2 = GUICtrlCreateLabel("Label1", 100, 110)
$Button4 = GUICtrlCreateButton("Label", 8, 40, 75, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Timer_Init", 8, 100, 75, 25, $WS_GROUP)
$Progress1 = GUICtrlCreateProgress(8, 72, 230, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
global $starttime = _Timer_Init()
global $i = 0
global $id = ""
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
	Case $GUI_EVENT_CLOSE
		Exit
	case $Button1
		_Timer_SetTimer($form1,500,"progress")
	case $Button2
		_Timer_KillTimer($form1,$id)
		guictrlsetdata($Progress1,0)
	case $Button3
		_Timer_KillAllTimers($form1)
		guictrlsetdata($Progress1,0)
	case $Button4
		_Timer_SetTimer($form1,1,"setlabel")
	case $Button5
		$id = _Timer_SetTimer($form1,100,"czas")
EndSwitch
WEnd
func czas($1,$2,$3,$4)
guictrlsetdata($Label2,_Timer_Diff($starttime))
EndFunc
func progress($1,$2,$3,$4)
if $i < 99 Then
for $i = 0 to 100
	guictrlsetdata($Progress1,$i)
Next
EndIf
EndFunc

func setlabel($1,$2,$3,$4)
guictrlsetdata($label1,123)
guictrlsetdata($label1,1234)
guictrlsetdata($label1,1235)
guictrlsetdata($label1,1236)
guictrlsetdata($label1,1237)
guictrlsetdata($label1,1238)
guictrlsetdata($label1,1239)
guictrlsetdata($label1,12310)
EndFunc

 

 

 

To by było na tyle:>

Opublikowano

nigdy nie stosowałem adbil register

ale według mnie timers jest szybszy i działa dopóki się nie wyłączy go

tzn robi się pętla nieskończona która można wyłączyć killtimers

@edit

zapomniałem dodac

nie działają w nim wszelkie funkcje blokujące skrypt

jak msgbox sleep itp(chodzi o adbilregister)

Opublikowano

Użycie AdlibRegister powoduje włączanie funkcji co ileś tam ms :)

Przykładowy kod:

AdlibRegister("funkcja", 1000); włącza funkcje funkcja co 1000ms (1 sekundę)

global $i = 0

while 1
sleep(5000)
wend

func funkcja()
$i += 1
tooltip($i)
endfunc

Pisałem od ręki, więc może być jakaś literówka :P

Dzięki tej funkcji w ToolTipie będzie się wyświetlała co sek liczba o 1 większa :)

Więc możemy osiągnąć jakąś tam wielowątkowość :)

Jeśli ustawimy kilka Adlib'ów to się będą wykonywać niezależnie od siebie :)

 

Jeśli chcesz wiedzieć więcej to polecam Help'a oraz

www.autoitscript.com

Opublikowano

Tutaj masz więcej (cały UDF) o Adlib :)

http://www.autoitscript.com/forum/topic/83967-multithreading-for-autoit-finally/

Chyba się przyda :P

  • 10 miesięcy temu...
Opublikowano

@up,

ale mają jedną zasadniczą różnicę.

Timery odmierzają czas, i mogą służyć do wielu rzeczy.

A adlib tylko włącza określoną funckję co określony czas, i po za tym nic nie robi.

 

 

PS. Długo kopałeś zanim znalazłeś ten temat?

Opublikowano

nie nie długo ;p

po prostu wyzej toczyla sie dyskusja co lepsze wiec powiedzialem poniewaz mi sie przypomnialo ;)

komus moze sie zawsze przydac ;p

  • 3 miesiące temu...
Opublikowano

Czy można użyć tej opcji z losowym czasem pomiędzy powtarzaniem czynności? Mam takie coś ale w tym przypadku akcja jest powtarzana równo co 8 sekund

 

$losuj = Random(2000, 15000, 1)
AdlibRegister("food", $losuj)

Opublikowano

Tak ale wymaga to sporo pieprzenia się.

 


Global $a = 0

AdlibRegister("a",Random(1,2000,1))


while Sleep(100)

ToolTip($a,0,0,"test")

WEnd


func a()

$a = $a +1
AdlibUnRegister("a")
AdlibRegister("a",Random(1,2000,1))
EndFunc




 

 

Zwróć uwage na to że $a rośnie nie równomiernie.

 

Natomiast Twój błąd polega na tym że chyba nie do końca rozumiesz jak działa funkcja Random.

 

Zwraca ona losową liczbe, ale po przypsaniu jej do zmiennej liczba która została zwrócona jest już znana, więc w miejsce $losuje zostanie podstawiona stała liczba - zwrócona przez funkce random. Nie będzie sie ona zmieniała automagicznie.

 

Może troche zamotałem ale mam nadzieje że rozumiesz o co mi chodzi.

Opublikowano

Nie prościej?

 

#include <Timers.au3>

Local $czas_powtarzania = Random(1, 10, 1)*1000
Local $timer = _Timer_Init()

While 1
If Int(_Timer_Diff($timer)) >= $czas_powtarzania Then
	MsgBox(64, "", "Wiadomość ukazała się po: " & $czas_powtarzania & " ms")
	$timer = _Timer_Init() ; powtorne odpalenie timera...
	$czas_powtarzania = Random(1, 10, 1)*1000 ; jesli nie chcemy zeby czas sie nie zmienial to usuwamy ta linijke
	TrayTip("Next...", "Następna wiadomość za: " & $czas_powtarzania & " ms", 1)
EndIf
Sleep(1) ; koniec cyklu ;d
WEnd

Opublikowano

/\

Dzięki bardzo, właśnie o takie coś mi chodziło. Korzystając z okazji, jak zatrzymać ową pętlę przyciskiem z GUI? Gdy zacznie się wykonywać ta pętle to z programy mogę wyjść jedynie gdy mam takie coś. Wtedy zamykam program. Chciałbym móc zatrzymać wykonywanie pętli przyciskiem z GUI zakończ.

HotKeySet("{ESC}", "off")

Func off()
   Exit
EndFunc   ;==>off

Opublikowano

Przycisk do zamykania to

$btnZAKONCZ = GUICtrlCreateButton("Zamknij", 35, 490, 100, 30)

 

W którym miejscu w poniższej funkcji należy wstawić ten fragment mający zakończyć tę funkcję

 

Func start1()
   $time1 = GUICtrlRead($hInput5)
   $time2 = GUICtrlRead($hInput6)
   Local $czas_powtarzania = Random($time1, $time2, 1) * 1000
   Local $timer = _Timer_Init()

   While 1
       If Int(_Timer_Diff($timer)) >= $czas_powtarzania Then
           $spell = GUICtrlRead(Random($hInput1, $hInput2, 1))
           ControlSend("Tibia", "", "", ($spell))
           ControlSend("Tibia", "", "", "{enter}")
           $timer = _Timer_Init() ; powtorne odpalenie timera...
           $czas_powtarzania = Random($time1, $time2, 1) * 1000
       EndIf
       ;Sleep(1)
   WEnd
EndFunc   ;==>start1

  • 6 miesięcy temu...
Opublikowano

...

 

to nie jest wielowatkowosc i nigdy żadnymi timerami ani funkcjami adlib nie wymusicie wykonywania kilku funkcji na raz, autoit zawsze wykonuje je po kolei, mozna tylko optymalizowac skrypt zeby dzialal szybciej. wiec nazwalbym ten temat raczej Optymalizacja autoita czy cos w ten deseń.

 

tak wiem że się czepiam i że temat trochę stary i odkopuje jakieś syfy, ale mnie to trochę zaskoczyło jak zobaczyłem napis Wielowatkowość na tym forum, bo już dawno by było głośno o tym na oficjalnym forum autoita.

 

poza tym, gdyby wielowątkowość działała, odpalilibyście więcej niż jednego msgboxa itp.

 

co do prawdziwej wielowątkowości, tutaj macie ciekawy skrypt ingerujący w proces autoita , odpala kilka msgboxów, jeden na drugim wiec se poprzesuwajcie żeby było widać ^^, dziwnie to działa ale jakoś działa i tworzy nowe wątki (5) lecz większego zastosowania niż kilka msgboxów to nie ma (chyba), no i czasem coś go szlag trafia i nie działa na skompilowanej wersji (mnie przynajmniej) :/ no ale to problem natury technicznej ^^ takie już jest autoit ;]

 

 

 

#include <winapi.au3>
$msgbox = DllCall("Kernel32.dll", "ptr", "GetProcAddress", "ptr", _WinAPI_GetModuleHandle("user32.dll"), "str", "MessageBoxW")
$msgbox = $msgbox[0]Local $codebuffers[5]
For $i = 0 To UBound($codebuffers)-1	$codebuffers[$i] = DllStructCreate("byte[1024]")
DllStructSetData($codebuffers[$i], 1, "0x6800000000680000000068000000006800000000b8" & SwapEndian($msgbox) & "ffd0c3")
$hThread = DllCall("Kernel32.dll", "ptr", "CreateThread", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($codebuffers[$i]), "ptr", 0, "dword", 0, "ptr", 0)
$hThread = $hThread[0]Next
While True
Sleep(100)
WEnd
Func SwapEndian($iValue)
Return Hex(BinaryMid($iValue, 1, 4))
EndFunc   ;==>SwapEndian

 

może ktoś z was pokombinuje i coś wymyśli

^^

  • 2 tygodnie później...
Opublikowano

Hmmm... temat stary, ale skoro siedzi na 1 stronie to chyba można napisać? :)

 

No więc tak, chciałbym odpalić 2 takie funkcje:

 

 



;Funkcja 1
Func tPod()
  $iiPod = GUICtrlRead($iPod)
		For $i = 1 To $iiPod
			_IENavigate($oIE, "***")
			_IELoadwait($oIE)
		   _IENavigate($oIE, "***")
			Local $timer = TimerInit()
			  Local $MaxTime = 20500
			  Do
			  $CurrentTime = TimerDiff($timer)
			  GUICtrlSetData($progress1, ($CurrentTime/$MaxTime*100))
			  Sleep(1)
		   Until $CurrentTime >= $MaxTime
		Next
		EndFunc

;Funkcja 2
Func tDosr()
		   $iiDosr = GUICtrlRead($iDosr)
		For $ii = 1 To $iiDosr
			_IENavigate($oIE, "****")
			_IELoadwait($oIE)
		   _IENavigate($oIE, "****")
			Local $timer = TimerInit()
			  Local $MaxTime = 20500
			  Do
			  $CurrentTime = TimerDiff($timer)
			  GUICtrlSetData($progress2, ($CurrentTime/$MaxTime*100))
			  Sleep(1)
			  Until $CurrentTime >= $MaxTime
		   Next
		EndFunc

 

Funkcje te miałby być odpalane z przycisku

Case
 $tPod
Case
 $tDosr

 

 

 

Kombinowałem z Timersami i nie działało, AdlibRegister też próbowałem tu wcisnąć i też nie działało

Ma ktoś pomysł dlaczego?

Opublikowano

@UP

 

Zaimplementuj sobie...

Pisane na szybko ;p

_Timer_SetTimer() to wywołanie startu timera, czyli wykonywania funkcji co pewien czas na oddzielnym wątku...

 

 

 

#include <Timers.au3>

Local $Timer1 = 1000 ; czas pomiedzy wykonywaniami funkcji 1
Local $Timer2 = 1000 ; czas pomiedzy wykonywaniami funkcji 2

; $Form = GUI
_Timer_SetTimer($Form, $Timer1, "tPod")
_Timer_SetTimer($Form, $Timer2, "tDosr")

;Funkcja 1
Func tPod($1, $2, $3, $4) ; // $1, $2, $3, $4 >> nie zmieniaj tego, to są watki, bez tego crash 
  $iiPod = GUICtrlRead($iPod)
					For $i = 1 To $iiPod
							_IENavigate($oIE, "***")
							_IELoadwait($oIE)
					   _IENavigate($oIE, "***")
							Local $timer = TimerInit()
							  Local $MaxTime = 20500
							  Do
							  $CurrentTime = TimerDiff($timer)
							  GUICtrlSetData($progress1, ($CurrentTime/$MaxTime*100))
							  Sleep(1)
					   Until $CurrentTime >= $MaxTime
					Next
					EndFunc

;Funkcja 2
Func tDosr($1, $2, $3, $4) ; // $1, $2, $3, $4 >> nie zmieniaj tego, to są watki, bez tego crash 
					   $iiDosr = GUICtrlRead($iDosr)
					For $ii = 1 To $iiDosr
							_IENavigate($oIE, "****")
							_IELoadwait($oIE)
					   _IENavigate($oIE, "****")
							Local $timer = TimerInit()
							  Local $MaxTime = 20500
							  Do
							  $CurrentTime = TimerDiff($timer)
							  GUICtrlSetData($progress2, ($CurrentTime/$MaxTime*100))
							  Sleep(1)
							  Until $CurrentTime >= $MaxTime
					   Next
					EndFunc

 

Opublikowano

Teraz mam tak:

 

 

Przyciski:


  	 Case $tPod
		;tPod()
		Local $Timer1 = 1000 ; czas pomiedzy wykonywaniami funkcji 1
		_Timer_SetTimer($Form1, $Timer1, "tPod")

	Case $tDosr
		;tDosr()
		Local $Timer2 = 1000 ; czas pomiedzy wykonywaniami funkcji 2
		_Timer_SetTimer($Form1, $Timer2, "tDosr")

 

Funkcje:

; $Form = GUI
_Timer_SetTimer($Form1, $Timer1, "tPod")
_Timer_SetTimer($Form1, $Timer2, "tDosr")

;Funkcja 1
Func tPod($1, $2, $3, $4) ; // $1, $2, $3, $4 >> nie zmieniaj tego, to są watki, bez tego crash 
  $iiPod = GUICtrlRead($iPod)
											For $i = 1 To $iiPod
															_IENavigate($oIE, "http://s7.footballteam.pl/trening_normal_ajax.php?sknew=2")
															_IELoadwait($oIE)
											   _IENavigate($oIE, "http://s7.footballteam.pl/trening_normal.php")
															Local $timer = TimerInit()
															  Local $MaxTime = 20500
															  Do
															  $CurrentTime = TimerDiff($timer)
															  GUICtrlSetData($progress1, ($CurrentTime/$MaxTime*100))
															  Sleep(1)
											   Until $CurrentTime >= $MaxTime
											Next
											EndFunc

;Funkcja 2
Func tDosr($1, $2, $3, $4) ; // $1, $2, $3, $4 >> nie zmieniaj tego, to są watki, bez tego crash 
											   $iiDosr = GUICtrlRead($iDosr)
											For $ii = 1 To $iiDosr
															_IENavigate($oIE, "http://s7.footballteam.pl/trening_normal_ajax.php?sknew=8")
															_IELoadwait($oIE)
											   _IENavigate($oIE, "http://s7.footballteam.pl/trening_normal.php")
															Local $timer = TimerInit()
															  Local $MaxTime = 20500
															  Do
															  $CurrentTime = TimerDiff($timer)
															  GUICtrlSetData($progress2, ($CurrentTime/$MaxTime*100))
															  Sleep(1)
															  Until $CurrentTime >= $MaxTime
											   Next
											EndFunc

 

 

 

I dalej nie działa.

Dokładnie to chodzi mi o to żeby 1 i 2 funkcje dało się wystartować po wciśnięciu 1 i 2 przycisku.

Przycisk1 -> Funkcja1

Przycisk2 -> Funkcja2

 

Tylko żeby to działało jeden po drugim tj. że jak klikne Przycisk1 to Funkcja1 odpala się, a jak przycisnę powiedzmy 3sek później (zanim Funkcja1 skończy swoje działanie) Przycisk2 To funkcja2 odpala się bez żadnego czekania.

(Tak wiem, niezrozumiałe, ale spaaać mi się chce... wstałem o 4 spać poszedłem o 3 :P, jbc to rano poprawie żeby było bardziej zrozumiałe)

 

BTW. Program zwiesza się kiedy progressbar dojdzie do 25% o.O I chwile później się odwiesza.

Aha... i limit lajków dla cb:)

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...