# Photon + SystemThread(Enabled) causing compile issues?

**URL:** <https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192>\
**Category:** Troubleshooting\
**Created:** [December 11, 2018, 11:43pm UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192 "2018-12-11T23:43:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [December 11, 2018, 11:43pm UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/1 "2018-12-11T23:43:15Z")

</div>

OK, I have a XBee library I’m using and it compiles and runs just fine in Particle DEV as seen in the screenshot below:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/3/33b82b895a223781210be65efb740b38d25b57e0.png)

Now when I try to add `SYSTEM_THREAD(ENABLED);` to the top of the sketch the compiler starts throwing the errors for some reason.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/4/841a8fb28fc2b776fd463ca5792a1a05cd399594.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/7/6709990f9ae1b7e735fe5639c967529c985cc040.png)

Any ideas why adding the System Thread command at the top of the sketch would cause these issues when otherwise without that command everything compiles and runs just fine?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 11, 2018, 11:59pm UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/2 "2018-12-11T23:59:25Z")

</div>

I’ve seen similar issues.  
Can you try putting `SYSTEM_THREAD(ENABLED)` _after_ your `#include` block?

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [December 12, 2018, 12:06am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/3 "2018-12-12T00:06:51Z")

</div>

Of course that fixed it 😊

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/b/3b4efb9f8e11e5f56b213b141942800cee21c263.jpeg)

I always thought that had to be called first so didn’t try it below the includes 🙂

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 12, 2018, 12:14am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/4 "2018-12-12T00:14:34Z")

</div>

I think the issue stems from the `#include <Particle.h>` statement that’s inside the header file you are including.  
Usually the preprocessor adds that include statement at the top of you code, when it’s not found, hence even if you write `SYSTEM_THREAD(ENABLED)` as top line in your `.ino` file that `#include <Particle.h>` will end up before it, but when you have `Particle.h` already there but after the “call” of the `SYSTEM_THREAD()` macro the compiler gets confused.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [December 12, 2018, 12:25am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/5 "2018-12-12T00:25:16Z")

</div>

I don’t have #include \<Particle.h\> At the top of the .ino or any of the .h or .cpp files.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 12, 2018, 12:26am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/6 "2018-12-12T00:26:56Z")

</div>

Then something else causes the preprocessor to trip and confuse the compiler 😉

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [December 12, 2018, 12:29am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/7 "2018-12-12T00:29:18Z")

</div>

Haven’t tried to compile using the Visual Studio setup yet although I do have it installed.

Wonder if it would have done the same.

Can I flash over Wifi easily with Visual Studio the same as I do with Particle Dev? Or is it more complicated than that?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 12, 2018, 12:38am UTC](https://community.particle.io/t/photon-systemthread-enabled-causing-compile-issues/46192/8 "2018-12-12T00:38:05Z")

</div>

> [@RWB](#):
>
> Can I flash over Wifi easily with Visual Studio the same as I do with Particle Dev? Or is it more complicated than that?

I think it's pretty much the same (maybe one/two extra clicks, but that will be stream lined).  
And you can falsh via USB and most importantly build without internet connection.

But editing, refactoring, maintenance, debugging (to come) is just that much better.  
I never was a Dev fan, but with Workbench I don't see any raison d'être for it anymore at all.
