<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Прерывание таймера другим таймером.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7421&amp;type=atom" />
	<updated>2012-08-04T13:32:57Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7421</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62362#p62362" />
			<content type="html"><![CDATA[<p><a href="http://l.autohotkey.net/docs/Variables.htm#Expressions">Expressions</a></p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-08-04T13:32:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62362#p62362</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62360#p62360" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>creature.ws пишет:</cite><blockquote><p>Т.е. причина - DeviceSearch()&nbsp; — функция.<br /><strong>Test := DeviceSearch() </strong> — достаточно.</p></blockquote></div><p>Думаю да знак % можно убрать хотя разницы я опять не заметил.</p>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-04T13:09:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62360#p62360</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62356#p62356" />
			<content type="html"><![CDATA[<p>Т.е. причина - DeviceSearch()&nbsp; — функция.<br /><strong>Test := DeviceSearch() </strong> — достаточно.</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-08-04T12:55:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62356#p62356</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62355#p62355" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>creature.ws пишет:</cite><blockquote><p>Будьте добры, уточните, что происходит в строке <strong>Test:= % DeviceSearch()</strong></p><p>Исходя из чего вы используете <strong>Test contains True</strong>, а не <strong>(test = true)</strong> или <strong>test = true</strong>?</p></blockquote></div><p>Прошу прощение, моя ошибка, можно использовать <strong>test = true</strong> разницы в работе скрипта я не заметил. Что касается <strong>Test:= % DeviceSearch()</strong> то тут пришлось так сделать ибо <strong>DeviceSearch()</strong> это функция (см. <a href="http://www.script-coding.com/AutoHotkey/Functions.html">http://www.script-coding.com/AutoHotkey/Functions.html</a>)</p>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-04T12:51:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62355#p62355</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62354#p62354" />
			<content type="html"><![CDATA[<p>Будьте добры, уточните, что происходит в строке <strong>Test:= % DeviceSearch()</strong></p><p>Исходя из чего вы используете <strong>Test contains True</strong>, а не <strong>(test = true)</strong> или <strong>test = true</strong>?</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-08-04T12:11:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62354#p62354</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62353#p62353" />
			<content type="html"><![CDATA[<p>господа всё таки я умудрился решить эту проблему привожу код:<br /></p><div class="codebox"><pre><code>
#Persistent
feq:= 10000
SetTimer, MainCheck, %feq%,1
MainCheck:
Test:=  DeviceSearch()
If Test = True
{
	Settimer,MainCheck,off	
	Sleep,%feq%
	Test:=  DeviceSearch()
	If test = True
	{
		MsgBox Remove Key.
	}
	SetTimer,MainCheck,on	
}
Return
DeviceSearch()
{
	Path:= A_WorkingDir &quot;\temp.txt&quot;
	RunWait, %comspec% /c Devcon find *usb\vid_1131* &gt;&gt;%path%, , Hide
	Result = False
	Loop, Read, %Path%
	{
		If A_LoopReadLine Contains VID_1131
		{
			Result = True
		}
	}
	FileSetAttrib -RH, %Path%
	FileDelete, %Path%
	Return  %Result%
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-04T12:05:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62353#p62353</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62344#p62344" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#Persistent
q := new CQueue(15)      ; число в скобках задаёт «длину очереди исполнения»

SetTimer, AddFunc1, 1000
SetTimer, AddFunc2, 4000
return

AddFunc1:
    q.Add(Func(&quot;Func1&quot;))
    return

AddFunc2:
    q.Add(Func(&quot;Func2&quot;))
    return

Func1() {
    MsgBox 1
}

Func2() {
    MsgBox 2
}

Class CQueue
{
    __New(lim) {
        this.lim := lim
    }

    Add(FuncParam*) {
        if this.MaxIndex() &gt;= this.lim
            return &quot;&quot;
        this.Insert(FuncParam)
        If this.Maxindex() = 1
            While this.MaxIndex()
                this[1, 1].(this[1]*), this.Remove(1)
    }
}</code></pre></div><p>Поведение по умолчанию:<br /></p><div class="codebox"><pre><code>#Persistent
SetTimer, Sub1, 1000
SetTimer, Sub2, 4000
return

Sub1:
    MsgBox 1
    return

Sub2:
    MsgBox 2
    return</code></pre></div><p>Запустите один из примеров подождите 16 секунд, нажмите «ОК».</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-08-04T09:19:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62344#p62344</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62340#p62340" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Korobkof пишет:</cite><blockquote><p>Передо мной встал такой же вопрос. Перепробовал все варианты, какие только пришли в голову. Приоритеты и critical отверг из-за того, что трудно предсказать поведение скрипта при наличии нескольких таймеров и необходимости точного срабатывания по времени некоторых из них.</p></blockquote></div><p>Тогда нужно строить свою очередь исполнения. Т.е. создать упорядоченный список, где хранятся функции, которые должны быть исполнены. А таймеры должны только добавлять в этот список данные. Таким образом можно решить какие функции будут выполнены раньше и избавиться от проблемы прерывания выполнения кода таймером(т.е. прерывать-то он будет как и прежде, но совсем не надолго и никак не влияя на окружение).</p>]]></content>
			<author>
				<name><![CDATA[Александр_]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24888</uri>
			</author>
			<updated>2012-08-04T08:32:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62340#p62340</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62338#p62338" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Naiglos пишет:</cite><blockquote><p>Есть скрипт в котором два таймера, проблема заключается в том, что таймер SecondCheck постоянно не даёт работать таймеру MainCheck. Вопрос: как решить эту проблему?</p></blockquote></div><p>Передо мной встал такой же вопрос. Перепробовал все варианты, какие только пришли в голову. Приоритеты и critical отверг из-за того, что трудно предсказать поведение скрипта при наличии нескольких таймеров и необходимости точного срабатывания по времени некоторых из них. Самым простым и надежным способом оказалось задать не кратные друг другу периоды. Поскольку в Вашем скрипте периоды таймеров много продолжительнее, чем время, необходимое для выполнения подпрограмм, должно сработать. Достаточно период второго таймера изменить на 8500 или 11500 - судя по содержанию скрипта, это не принципиально.<br />&nbsp; &nbsp; &nbsp;Для случаев, когда это не сработает, держу в голове вариант сохранения в отдельной переменной времени последнего срабатывания таймера, чтобы другой таймер перед запуском подпрограммы мог определить, сколько осталось до запуска первого и успеет ли до этого момента выполниться подпрограмма. (Кстати, а почему нет такой встроенной переменной? В описании таймера говорится как можно сбросить ее в 0, но в списке встроенных переменных я не нашел такой.) В простых случаях это вроде как не сулит проблем, а вот при перезагрузках скрипта, включении/выключении таймеров и т.д. придется отдельно засекать время простоя.</p>]]></content>
			<author>
				<name><![CDATA[Korobkof]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28148</uri>
			</author>
			<updated>2012-08-04T08:10:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62338#p62338</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62332#p62332" />
			<content type="html"><![CDATA[<p>ypppu,&nbsp; Я так понимаю вы имеете в виду параметр Priority если это так, то я пробовал выставлять различные значения, но нечего не изменилось.</p>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-03T22:47:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62332#p62332</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62331#p62331" />
			<content type="html"><![CDATA[<p>[quote=Проект перевода документации AutoHotkey<br />Ник переводчика: semechka]<strong>Приоритет потоков</strong><br />Любая горячая клавиша, подпрограмма по таймеру или элемент пользовательского меню с приоритетом ниже, чем у текущего потока, не может прервать его. В течение этого времени такие таймеры не будут работать, а нажатие определенной горячей клавиши или выбор определенного элемента пользовательского меню не будет иметь эффекта (или будет буферизовано).</p></blockquote></div><p>Видимо, таймер, запускающий подпрограмму SecondCheck, имеет более высокий приоритет и не может быть прерван.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2012-08-03T22:38:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62331#p62331</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62329#p62329" />
			<content type="html"><![CDATA[<p>Господа, так что же мне тогда делать?</p>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-03T20:48:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62329#p62329</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62328#p62328" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>ypppu пишет:</cite><blockquote><p>Это не проблема, а особенность команды <em>SetTimer</em>. <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /></p></blockquote></div><p>Одно не исключает другое <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />. <br />Это уже много раз обсуждалось- многопоточности, как таковой, в AHK нет, но в большинстве случаев она и не нужна. Например критическая секция прерываться не будет.</p>]]></content>
			<author>
				<name><![CDATA[Александр_]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24888</uri>
			</author>
			<updated>2012-08-03T20:14:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62328#p62328</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62327#p62327" />
			<content type="html"><![CDATA[<p>Это не проблема, а особенность команды <em>SetTimer</em>. <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /><br />[quote=Проект перевода документации AutoHotkey<br />Имена переводчиков Дед Мазай, Gourmet<br />]Хотя таймеры могут создать впечатление того, что скрипт выполняет несколько задач одновременно, это не так. Напротив, спланированная по времени подпрограмма ведет себя точно так же, как и любой другой поток: она может прервать какой-либо поток или быть прерванной другим потоком, например таким, как подпрограмма горячей клавиши.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2012-08-03T19:13:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62327#p62327</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Прерывание таймера другим таймером.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=62325#p62325" />
			<content type="html"><![CDATA[<p>Есть скрипт в котором два таймера, проблема заключается в том, что таймер SecondCheck постоянно не даёт работать таймеру MainCheck.<br />Вопрос: как решить эту проблему?<br /></p><div class="codebox"><pre><code>
#Persistent
Gosub, MainCheck
SetTimer, MainCheck, 15000,1
MainCheck:
If % DeviceSearch() contains True
{
	SetTimer, SecondCheck, 10000,2	
	Return
}
Return
SecondCheck:
If % DeviceSearch() contains True
{
	
	MsgBox Remove Key.
}
Return
DeviceSearch()
{
	Path:= A_WorkingDir &quot;\temp.txt&quot;
	RunWait, %comspec% /c Devcon find *usb\vid_1131* &gt;&gt;%path%, , Hide
	Result = False
	Loop, Read, %Path%
	{
		If A_LoopReadLine Contains VID_1131
		{
			Result = True
		}
	}
	FileSetAttrib -RH, %Path%
	FileDelete, %Path%
	Return  %Result%
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Naiglos]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28443</uri>
			</author>
			<updated>2012-08-03T18:38:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=62325#p62325</id>
		</entry>
</feed>
