add wait thread
This commit is contained in:
+42
-2
@@ -10,8 +10,10 @@ using System.ComponentModel;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.ServiceProcess;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ namespace SafeBagDE70
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
WaitSQLStart();
|
||||||
CDMSTATE = new CDMSTATE();
|
CDMSTATE = new CDMSTATE();
|
||||||
DeviceStatus = new DeviceStatus
|
DeviceStatus = new DeviceStatus
|
||||||
{
|
{
|
||||||
@@ -53,8 +56,6 @@ namespace SafeBagDE70
|
|||||||
OtherError = 0,
|
OtherError = 0,
|
||||||
};
|
};
|
||||||
InitUsers();
|
InitUsers();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -72,6 +73,7 @@ namespace SafeBagDE70
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
customerAccounts = new List<CustomerAccount>();
|
customerAccounts = new List<CustomerAccount>();
|
||||||
using (var context = new CDMDbContext())
|
using (var context = new CDMDbContext())
|
||||||
{
|
{
|
||||||
@@ -101,6 +103,44 @@ namespace SafeBagDE70
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private static void WaitSQLStart()
|
||||||
|
{
|
||||||
|
string serviceName = "MSSQLSERVER"; // Default SQL Server service name, change if necessary
|
||||||
|
|
||||||
|
// Create a ServiceController instance for the SQL Server service
|
||||||
|
ServiceController serviceController = new ServiceController(serviceName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Information("Checking the status of the SQL Server service...");
|
||||||
|
|
||||||
|
// Loop to wait until the service is running
|
||||||
|
while (serviceController.Status != ServiceControllerStatus.Running)
|
||||||
|
{
|
||||||
|
//if (serviceController.Status == ServiceControllerStatus.Stopped)
|
||||||
|
//{
|
||||||
|
// Log.Information("SQL Server service is stopped. Starting it...");
|
||||||
|
// serviceController.Start();
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Refresh the controller to get the updated status
|
||||||
|
serviceController.Refresh();
|
||||||
|
|
||||||
|
Log.Information($"Current status: {serviceController.Status}");
|
||||||
|
Thread.Sleep(5000); // Wait for 5 seconds before checking again
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Information("SQL Server service is running successfully.");
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: Could not access the service '{serviceName}'. {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static CDMSTATE? CDMSTATE = null;
|
public static CDMSTATE? CDMSTATE = null;
|
||||||
private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time
|
private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
|
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
|
||||||
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
||||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||||
|
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user