1. Restart method
();
After testing, it is found that sometimes the program will only be closed and will not restart.
2. () and Exit()
(().Location); ();
After testing, it is found that sometimes the program will only be closed and will not restart.
3. Start and Kill methods of the process
(().Location); ().Kill();
After testing, it is relatively stable to restart using the process.
//Open new instance(); //Close the current instance().Kill(); ();//Exit the current project. If it is a sub-project, the main project will not be stopped(0);//Stop all projects
Four: Use Process
Process p = new Process(); = + “”; = false; (); ();
Not tested.
Restart with parameters
Process proc = new Process(); = @""; = "\"C:\\My Docs\\SomeDirectory\\\""; ();
repair
My database structure:
GO /****** Object: Table [dbo].[RestartLog] Script Date: 09/04/2023 20:45:07 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[RestartLog]( [Id] [int] IDENTITY(1,1) NOT NULL, [RestartDate] [datetime] NULL, [ThisPCName] [nvarchar](80) NULL, [IPAdd] [nvarchar](80) NULL, [CreateDate] [datetime] NULL ) ON [PRIMARY] GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Restart time' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RestartLog', @level2type=N'COLUMN',@level2name=N'RestartDate' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Computer Name' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RestartLog', @level2type=N'COLUMN',@level2name=N'ThisPCName' GO ALTER TABLE [dbo].[RestartLog] ADD CONSTRAINT [DF_RestartLog_CreateDate] DEFAULT (getdate()) FOR [CreateDate] GO
My DAL processing operation method:
/// <summary> /// Main data operations /// </summary> /// <returns></returns> public ResultMsg InsertAndUpdate(int HourRestart) { ResultMsg msg = new ResultMsg(); try { string SqlStr = $@" DECLARE @IPadd nvarchar(80); ---Ipaddress DECLARE @PCName nvarchar(100); --Computer name DECLARE @TempId int ;--0No data,1Time has not come,2Need to restart DECLARE @OutInt int;---Return data DECLARE @RestartHour int;---Restart time Select @IPadd= CONVERT( nvarchar(80) ,CONNECTIONPROPERTY('CLIENT_NET_ADDRESS') ) ; Select @PCName= HOST_NAME(); set @RestartHour={HourRestart}; if exists( SELECT * FROM [RestartLog] WHERE [IPAdd] = @IPadd ) begin if exists( SELECT * FROM [RestartLog] WHERE [IPAdd] = @IPadd and datediff(hour,RestartDate,getdate())>@RestartHour) begin update [RestartLog] set RestartDate = GETDATE() WHERE [IPAdd] = @IPadd and datediff(hour,RestartDate,getdate())>@RestartHour; set @OutInt = 2;--Need to restart end else begin set @OutInt = 1;--Time has not come不需要Need to restart end end else ----No data,Need to insert data begin insert [RestartLog] ( [RestartDate] ,[ThisPCName] ,[IPAdd],[CreateDate]) values (GETDATE(),@PCName,@IPadd,GETDATE()); set @OutInt = 0; end select @OutInt; "; = <int>(SqlStr); = true; } catch (Exception ex) { = false; = ; } return msg; }
This is the end of this article about the implementation of c# regular restarting program operations. For more related c# regular restarting content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!