# Script vs scan class

**URL:** <https://forum.inductiveautomation.com/t/script-vs-scan-class/18564>\
**Category:** Ignition\
**Created:** [June 21, 2018, 4:04pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564 "2018-06-21T16:04:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vince](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@Vince](https://forum.inductiveautomation.com/u/Vince)\
**Post date:** [June 21, 2018, 4:04pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/1 "2018-06-21T16:04:44Z")

</div>

Hi,

If a script in a tag’s value change event take a long time to execute, will it stop the refresh of all the tags from the same scan class?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2018, 5:56pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/2 "2018-06-21T17:56:20Z")

</div>

Possibly. Depends on what else is going on, I believe. Use a gateway tag change event script instead of a tag event–value change. The former allows you to specify a dedicated thread.

---

<div class="post-metadata">

**Author:** ![Vince](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@Vince](https://forum.inductiveautomation.com/u/Vince)\
**Post date:** [June 21, 2018, 6:30pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/3 "2018-06-21T18:30:58Z")

</div>

I understand. But we extensibly use UDT and some tags in the UDT contain value change script. The goal is to not have to create individual script.

Does system.util.invokeAsynchronous works in value change script? I could use that to call function that can be long to execute.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2018, 6:43pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/4 "2018-06-21T18:43:13Z")

</div>

> [@Vince](#):
>
> The goal is to not have to create individual script.

You don't. You simply add the tag to the list for the one tag change event. If you really want to minimize code duplication, tag change events are far superior to tag events.

> [@Vince](#):
>
> Does system.util.invokeAsynchronous works in value change script? I could use that to call function that can be long to execute.

Should work. But you loose the overlapping event protection that the tag change event script automatically provides.

---

<div class="post-metadata">

**Author:** ![Vince](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@Vince](https://forum.inductiveautomation.com/u/Vince)\
**Post date:** [June 21, 2018, 7:10pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/5 "2018-06-21T19:10:21Z")

</div>

I did a small test.

I create 3 tags using the same scan class.:

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f6dab8411a5473f32b9aff820f3f64c1d030920a.png)

One of the tags is an OPC tag. I read a flashing bit in a plc. The scrip tag is a memory tag. When it vlaue change, a script write its value in the written tag after some delay with a while loop (worst case). Here is the code:

```
counter = 0
otherEvent = 0
while 1:
    counter += 1
    if counter >= 100000000:
        break  	
system.tag.write("[.]WrittenTag",currentValue.value)

```

Then, when I toogle the ScriptTag, the OPCtag continue to flash. So it seems the script in the ScriptTag does not affect the scan class.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 1, 2019, 11:29am UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/6 "2019-04-01T11:29:16Z")

</div>

> [@pturmel](#):
>
> Possibly. Depends on what else is going on, I believe. Use a gateway tag change event script instead of a tag event–value change. The former allows you to specify a dedicated thread.

Where? (The former allows you to specify a dedicated thread)

 ![FGateway%20Tag%20Change%20Scripts](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4ecd07f6690b04f651f210f0ea16f691ab4cddd7.png)

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [April 1, 2019, 11:44am UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/7 "2019-04-01T11:44:41Z")

</div>

As far as I can see, this is only possible for Gateway Timer Scripts, not Gateway Tag Change Scripts.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 1, 2019, 12:28pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/8 "2019-04-01T12:28:22Z")

</div>

Huh. Missed that. Sorry @zxcslo. ☹

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 1, 2019, 12:37pm UTC](https://forum.inductiveautomation.com/t/script-vs-scan-class/18564/9 "2019-04-01T12:37:59Z")

</div>

If you really need a dedicated thread, I would create my own executor in a script module, with a function to submit a custom runnable with your event object. See [later.py](https://www.automation-pros.com/ignition/later.py) for an example.
