Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reboot/Shutdown causes IOException #100

Open
Deantwo opened this issue Mar 7, 2024 · 1 comment
Open

Reboot/Shutdown causes IOException #100

Deantwo opened this issue Mar 7, 2024 · 1 comment

Comments

@Deantwo
Copy link
Contributor

Deantwo commented Mar 7, 2024

Using the /system/reboot or /system/shutdown command will cause an IOException. Not sure what would be a good solution to this issue.

>/system/reboot
<
<
Exception thrown: 'System.IO.IOException' in tik4net.dll
>/quit
<
<
System.IO.IOException: Can not read sentence from connection
   at tik4net.Api.ApiConnection.ReadSentence()
   at tik4net.Api.ApiConnection.GetOne(String tag)
   at tik4net.Api.ApiConnection.<GetAll>d__54.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at tik4net.Api.ApiConnection.CallCommandSync(String[] commandRows)
   at tik4net.Api.ApiCommand.ExecuteNonQuery()
   at ...

Example code:

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);
ITikCommand cmd = conn.CreateCommand("/system/reboot");
System.Diagnostics.Debug.WriteLine("Executing reboot");
cmd.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine("Reboot executed");
@Deantwo
Copy link
Contributor Author

Deantwo commented Dec 2, 2024

Found a workaround that seems to work ok.

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);
System.Diagnostics.Debug.WriteLine("Executing reboot");
conn.Connection.CallCommandAsync(new List<string> { "/system/reboot" }, "reboot", null);
System.Diagnostics.Debug.WriteLine("Reboot executed");

Basically using the CallCommandAsync method directly and setting the callback action to null.

Slightly worried that ApiConnection.cs#L503 will result in an infinite loop in the background, but it should stop as long as the connection is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant