emoacht / Monitorian

A Windows desktop tool to adjust the brightness of multiple monitors with ease
https://www.microsoft.com/store/apps/9nw33j738bl0
MIT License
3.3k stars 154 forks source link

Calling from an external progams causes a failure #613

Closed ajitid closed 1 month ago

ajitid commented 1 month ago

I am essentially calling monitorian /set <displayid> <num> command from Golang. And when I call it many times in succession I get this:

Named pipe client failed.
System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Pipe is broken.
   at System.IO.Pipes.PipeStream.WinIOError(Int32 errorCode)
   at System.IO.Pipes.PipeStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Pipes.PipeStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.set_AutoFlush(Boolean value)
   at StartupAgency.PipeHolder.<ConnectServerAsync>d__17.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task1.get_Result()
   at StartupAgency.PipeHolder.Create(String[] args)
---> (Inner Exception #0) System.IO.IOException: Pipe is broken.
   at System.IO.Pipes.PipeStream.WinIOError(Int32 errorCode)
   at System.IO.Pipes.PipeStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Pipes.PipeStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.set_AutoFlush

After which calling monitorian commands from CLI doesn't give me any output. I have to restart monitorian to get output. The tray windows work as usual though.

I have a monitor attached to a laptop and both have separate working screens.

emoacht commented 1 month ago

Thank you for reporting. How many and how often have you sent the commands?

ajitid commented 1 month ago

I'm just pressing my keyboard arrows to invoke them so really not too many. The easiest way to reproduce this is to first call monitorian /get with a display id followed by a monitorian /set with an id and do this again and again. Another thing that I've noticed is sometimes monitorian /get gives -1 as the brightness during these invocations.

emoacht commented 1 month ago

If you just want to change the brightness from keyboard, keyboard shortcut is more appropriate. -1 means the value cannot be obtained.

ajitid commented 1 month ago

What are the possible causes when value can't be obtained (cli gives -1 even when monitorian is properly functioning)?

emoacht commented 1 month ago

A monitor is unexpectedly delicate. It easily fails to respond to a command typically immediately after power on and resume. It all up to each monitor.

ajitid commented 1 month ago

Ah ok. I don't have anything else to add beside that I was using SDL2 and when I put a logic to cap framerate, the issue stopped happening. So I can't pinpoint what causes this really apart from the symptoms I described above.

PS: I have deleted my comment on Defer change until stopped. Feel free to delete yours too.