[C# - VB] How to restart program in Winform

Xin chào các bạn, bài viết này mình sẽ hướng dẫn các bạn cách khởi động lại chương trình ứng dụng C#, Visual Basic, Winform.

[C# - VB] Hướng dẫn khởi động lại chương trình ứng dụng winform

[C# - VB] Hướng dẫn khởi động lại chương trình ứng dụng winform

Các bạn sử dụng đoạn script sau để thực hiện khởi động lại ứng dụng của mình:

FULL CODE CSHARP:

private void RestartProgram()
{
    // Get file path of current process 
    var filePath = Assembly.GetExecutingAssembly().Location;
    //var filePath = Application.ExecutablePath;  // for WinForms
 
    // Start program
    Process.Start(filePath);
     
    // For Windows Forms app
    Application.Exit();
                 
    // For all Windows application but typically for Console app.
    //Environment.Exit(0);
}

FULL CODE VISUAL BASIC:

Private Sub RestartProgram()
    Dim filePath = Assembly.GetExecutingAssembly().Location
    Process.Start(filePath)
    Application.[Exit]()
End Sub

Chúc các bạn thành công với thủ thuật đơn giản này.

Đăng nhận xét

Mới hơn Cũ hơn