Tray App no output

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

Restarted my PC, works as expected.

Weird behavior.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tray App no output

Post by jvierra »

No. This is something that every developer learns. When building and debugging the system can become unpredictable. Also having multiple notifications stacked and not removed can cause the icon group be have oddly. This is likely due to running under a debugger but can be caused by certain coding. The icon group and the system notification software can get at odds. Some code in an icon is executed by a callback to the program that created the icon. This can cause the thread that is called back into to get stuck in memory. That can make the notification system behave oddly. Rebooting or logging of and on will clear this most of the time. Making system calls inside the callback delegate can aggravate this to the point of requiring a reboot.

The reason I like to see that code is that I am usually pretty good at seeing where the code is misbehaving. Of course a debugger induced issue will not be visible in the code.

Anyway - it is good you resolved the issue so easily. If the issue returns we will have to see your code to see what might be causing this.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

Hello,
I wanted to note, this application was the first thing I started working on when I turned on my PC.. While your points are valid, I just wanted to point that out. I did put my code in my OP but incase, I've made changes to it today. I'm looking to not compress-archive if powershell studio is running.. This isn't happening :D
  1. function LoadFile{
  2.     $global:File = (!(Get-Process -Name 'PowerShell Studio' -ErrorAction SilentlyContinue))
  3. }
  4.  
  5. while($false)
  6. {
  7.  
  8.    
  9.     Write-Host "Kompressor Starting..."
  10.     LoadFile
  11.    
  12.     $Options = @(
  13.         "/E",
  14.         "/l"
  15.     )
  16.     $rclog = Robocopy "C:\users\tech\Documents\SAPIEN" \xxx $Options
  17.     $rclog | out-file C:\users\tech\Documents\SAPIEN\Filecount.txt
  18.     Compress-Archive -Path C:\users\tech\Documents\SAPIEN -DestinationPath C:\Windows\Utilities\Sapien.zip -CompressionLevel NoCompression -Update
  19.     Write-Host "Kompressor Completed..."
  20.     Start-Sleep -Seconds 1800
  21. }
  22.  
  23.  
  24. while ($true)
  25. {
  26.     Write-Host "Reseting timer..."
  27.     Start-Sleep 10
  28. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tray App no output

Post by jvierra »

But the code you posted has nothing to do with notify icon. It is just some code that compresses a file and sleeps for 30 minutes. That is very odd and can cause issues if an event is blocking like that.

Also the loop in the code will never run.

while ($false) {

This statement will never allow the contents to run.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

I don't think you're following what I'm asking.. I'm looking to build a Windows Tray App... btw this code is now working for me.. I had the logic wrong
  1. function LoadFile{
  2.     $global:File = (Get-Process -Name 'PowerShell Studio' -ErrorAction SilentlyContinue)
  3. }
  4.  
  5. while ($true)
  6. {
  7.     Write-Host "Kompressor Starting..."
  8.     LoadFile
  9.     #If PowerShell Studio is not running, perform compression.
  10.     if (!($File))
  11.     {
  12.        
  13.         $Options = @(
  14.             "/E",
  15.             "/l"
  16.         )
  17.         $rclog = Robocopy "C:\users\tech\Documents\SAPIEN" \xxx $Options
  18.         $rclog | out-file C:\users\tech\Documents\SAPIEN\Filecount.txt
  19.         Compress-Archive -Path C:\users\tech\Documents\SAPIEN -DestinationPath C:\Windows\Utilities\Sapien.zip -CompressionLevel NoCompression -Update
  20.         Write-Host "Kompressor Completed..."
  21.         Start-Sleep -Seconds 1800
  22.     }
  23.     #If powershell studio is running,
  24.     else
  25.     {
  26.         Start-Sleep -Seconds 10
  27.         Write-Host "Close PowerShell Studio..."
  28.         Start-Sleep -Seconds 10
  29.         Write-Host "Reseting timer..."
  30.     }
  31. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tray App no output

Post by jvierra »

JohnTitor wrote: Wed Mar 27, 2019 9:23 am I don't think you're following what I'm asking.. I'm looking to build a Windows Tray App... btw this code is now working for me.. I had the logic wrong
I posted an example of a tray app (really a NotifyIcon Form) earlier. Somewhere I have a demo of a non-form icon script that posts messages to the system notification center and shows how to add menu items to the tray icon. The method is much the same as the form example.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

I just downloaded your first posts example

when I build it.. It just shows the icon..

To be clear, my toast notifications are working and using the Windows Tray App script engine seems to be working well :D
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

Just as a last post.. I've found that BurntToast does notifications much slicker

https://www.powershellgallery.com/packa ... oast/0.6.3
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tray App no output

Post by jvierra »

Now that is real "Toast". It provides a complete wrapper and decent commands. I also have that module and have for a very long time. I still prefer to hand code this as many apps do not layout the same way.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Tray App no output

Post by apowershelluser »

I just found the fact I can add an icon cool.. its the little things.. now I'm just stuck on detecting if my flash drive is detected or not... I'm thinking that will be a do while script
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked