ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you have nested event loops?

Can I design my program to have nested event loops?
0 Kudos
Message 1 of 15
(3,985 Views)
Hi,

That doesn't seem to work. You might even have to close LV with task manager
if you'd try it. Instead, you could put an array of previous events in a
shift register through the event structure. That way, you can analyse
previous events, and act like it's nested.

Regards,

Wiebe.


"Boeing" wrote in message
news:50650000000800000088C80000-1079395200000@exchange.ni.com...
> Can I design my program to have nested event loops?
0 Kudos
Message 2 of 15
(3,985 Views)
Event structures are not intended to be nested. I suspect that your problem can be easily handled without nesting the event structure. There are several possible ways in which this can be handled depending upon exactly what you are trying to accomplish. With a more detailed description of what you are trying to do, finding the right solution shouldn't be difficult.
Message 3 of 15
(3,985 Views)

You're right. Just wanted to add my $0.2 that a few ways, or design patterns to handle such situations are the "producer-consumer" and "master-slave" patterns.

These patterns' templates can be found in your LabVIEW folder at:
LabVIEW_main_folder\templates\Frameworks\DesignPatterns

Hope this helps.

Khalid

0 Kudos
Message 4 of 15
(3,984 Views)
I have successfully used nested event loops. You have to be careful that events in outer loops do not occur (usually by disabling controls) while processing an inner loop event.

Bill F
0 Kudos
Message 5 of 15
(3,984 Views)
I also successfully nested event loops. And I was as careful as you are.
Things are working without a glitch.

I was wondering was it only me who has been coding that ? Now I have an answer.
0 Kudos
Message 6 of 15
(3,986 Views)
Well I too am glad someone else is doing it (especially someone with a medal next to their name 🙂 ). The NI doc for events does not specifically caveat against nested loops. Is there some official opinion?

Bill F
0 Kudos
Message 7 of 15
(3,984 Views)
The only warnings that I am aware of are about having more than one event structure in a vi in different while loops, for obvious reasons.
In my case, my event structures are in a vi and calls other sub vi's that has event stuctures, etc.
With proper control, only one event request is active at a time.
I would be glad to hear opinions from others too.
0 Kudos
Message 8 of 15
(3,984 Views)
You can nest event structures (it is allowed), but it is tricky, and could
crash, or at least show some unexpected behaviour. To me, that means it's
not working...

So "Can I design my program to have nested event loops?".. You can, but you
shouldn't (or I wouldn't)...

And the help does specify a caveat against nested loops:

"Avoid placing two Event structures in one loop. " (help>Event structures,
caveats)

This also means two event structures inside each other...

Regards,

Wiebe.


"bfarley" wrote in message
news:506500000005000000549D0100-1079395200000@exchange.ni.com...
> Well I too am glad someone else is doing it (especially someone with a
> medal next to their name 🙂 ). The NI doc for events does not
> specifi
cally caveat against nested loops. Is there some official
> opinion?
>
> Bill F
0 Kudos
Message 9 of 15
(3,985 Views)
"Avoid placing two Event structures in one loop. " (help>Event structures,
caveats)

No mention of nested loops in that. It is about event structures in parallel.

Any way, even nested event structures will create problems if not coded properly.
0 Kudos
Message 10 of 15
(3,984 Views)