I faced a very weird situation. I'm working on an C# WPF application with MVVM pattern. The app has a page from where user can change system time. And there is a NEXT button, which is binded to an AsyncCommand.
The problem occurs when I press the NEXT button. The system time is updated (both date & time values), but right after that, the NEXT button freezes. It is visible, but the command has stopped working. However, I have another CANCEL button which is still available and works perfectly fine.
Could be something similar to this question: SystemClock freezes the system, but I couldn't find a potential cause or solution.
I tried to set system time in 2 ways: one using the SetSystemTime() API and the other one using a Powershell cmdlet. For both cases it ended up with that freezed NEXT button.
For any other cmdlets, the application works fine.
Does anybody faced the same situation ?
[UPDATE with code]:
public void SetSystemDatetime(string selectedDate, string selectedTime)
{
var process = StartPowershellProcess($"Set-Date -Date '{selectedDate} {selectedTime}'");
process.WaitForExit();
}
private static Process StartPowershellProcess(string arguments)
{
var startInfo = new ProcessStartInfo("powershell.exe")
{
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
Verb = "runas",
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = Process.Start(startInfo);
return process;
}
Actual cmdlet: Set-Date -Date 'MM-dd-yyyy HH:mm'