Microsoft Developer Network > 포럼 홈 > .NET Base Class Library > How to use Application.Restart
질문하기질문하기
 

답변됨How to use Application.Restart

  • 2009년 11월 2일 월요일 오후 3:00KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi everyone,

    I have an application that has a Sign Off button. Is the application.restart suitable for this purpse? Can I make it work with the click event of a button? I have a link to some information but I am not sure how to implement this in my code.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.application.restart.aspx

    So to use this all I need is a

    Public Shared Sub Restart

    and then at the click event I code Application.Restart?

    But I am not sure what goes in the Restart Sub.

    Can someone help please??

    Thanks,

    Katlyn

답변

  • 2009년 11월 2일 월요일 오후 3:03Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hi,

    You dont need to write a sub named Restart. Just call Application.Restart() at your button click.
    • 답변으로 표시됨KatlynD 2009년 11월 4일 수요일 오후 6:25
    •  
  • 2009년 11월 4일 수요일 오후 2:39Heslacher 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
    Hi again,

    then it should really work, because its implemented since NET 2.0. Try to create a new windows forms project, add one button on the form. Then paste the code below:

    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            System.Windows.Forms.Application.Restart()
        End Sub
    End Class
    
    

    i am also using VB 2005 and it works like a charme.

    Edit: Also search in the Object browser for Restart you should find 1 method

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

모든 응답

  • 2009년 11월 2일 월요일 오후 3:03Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hi,

    You dont need to write a sub named Restart. Just call Application.Restart() at your button click.
    • 답변으로 표시됨KatlynD 2009년 11월 4일 수요일 오후 6:25
    •  
  • 2009년 11월 2일 월요일 오후 3:17KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    Hi,

    If I do the following:

    Private Sub MenuItemSignOff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItemSignOff.Click
      Application.restart()
    End Sub
    
    I get this error:

    'restart' is not a member of 'System.Windows.Forms.Application'. 
  • 2009년 11월 2일 월요일 오후 5:09Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Is your application .net framework 1.1 application.

    Application.Restart method is in framework since 2.0 version.
  • 2009년 11월 2일 월요일 오후 7:00KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I believe its version 2.0.

    I am using Visual Studio 2005 and when I go to Project Properties > References Tab, each item listed says 2.0 under version except for the last item, which is another Project called VControls that is being referenced and it is version 1.0. Would that matter?

    The System.Windows.Forms says version 2.0.
  • 2009년 11월 2일 월요일 오후 8:16Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    This is my form and it works fine,

    Could you try like this,

    Imports System.IO
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           
    
        End Sub
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            System.Windows.Forms.Application.Restart()
        End Sub
    End Class
    
  • 2009년 11월 3일 화요일 오후 5:49Tergiver 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    restart is not a member of Application, but Restart is.

    Sounds like a caseing problem?
  • 2009년 11월 4일 수요일 오후 1:37KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    So at the top of my form I have

    Imports System.IO
    
    included and then here is my button click.

    Private Sub MenuItemSignOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemSignOff.Click
        System.Windows.Forms.Application.Restart()
    End Sub
    
    And it is still giving me the message: Error 5 'Restart' is not a member of 'System.Windows.Forms.Application'. 


    In my project properties, under the references tab, does it have to say System.IO in the top section under References? On the bottom portion where it says Imported Namespaces, System.IO is in the list, but is not checked. Would any of this be creating the problem?

    (I can't seem to add System.IO, if I check the box, the Add User Import does not become enabled.)
  • 2009년 11월 4일 수요일 오후 2:00Heslacher 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi KatlynD,

    which version of VB do you use ?
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • 2009년 11월 4일 수요일 오후 2:34KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I am using Visual Studio 2005
  • 2009년 11월 4일 수요일 오후 2:39Heslacher 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
    Hi again,

    then it should really work, because its implemented since NET 2.0. Try to create a new windows forms project, add one button on the form. Then paste the code below:

    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            System.Windows.Forms.Application.Restart()
        End Sub
    End Class
    
    

    i am also using VB 2005 and it works like a charme.

    Edit: Also search in the Object browser for Restart you should find 1 method

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • 2009년 11월 4일 수요일 오후 4:12KatlynD 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi,

    Ok, so that worked, and then I thought of something. I am creating an application for a mobile device. This could be the problem perhaps?

    Sorry I didn't think of this sooner. I never thought to mention it. Do you know if there would be a way around this?? Or should I post to the Windows Mobile Development forum?
  • 2009년 11월 4일 수요일 오후 6:09Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi,

    It's better to ask there.

    Btw hope this helps.

    http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx
  • 2009년 11월 4일 수요일 오후 10:34JaedenRuiner 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Actually, I'll let ya'll in on a little secret that is very annoying with VB versus C#.  VB uses the My extensions application model, as well as little annoyance of Namespace inference. 

    So.  Say a C# App is like this:

    using System;
    using System.IO;
    using System.Data;

    VB
    Imports System;
    Imports System.IO;
    Imports System.Data;

    Now.  Because of Inference this is legal in VB:

    dim Path as String = "C:\Program Files\MyFileName.txt"
    dim FileName as String = IO.Path.GetFileName(Path)

    In C# this is ILLEGAL
    string Path = @"C:\Program Files\MyFileName.txt";
    string FileName = IO.Path.GetFileName(Path);
    however you can do:  string FileName = System.IO.Path. GetFileName(Path);
    and then it will work.   C# does not infer the System namespace, same as vb you can also do SqlClient.SqlCommand.  for C# you'd either have to explicitly declare using System.Data.SqlClient, or you'd have explicitly execute System.Data.SqlClient.SqlCommand.<whatever> 

    This is where that inference comes into play with the My namespace application model, especially when you are in a Windows Forms application just using:

    Application.<WhateverMethodHere>

    This causes VB to AUTOMATICALLY infer the My namespace.  And therefore My.Application.Restart does not exist.  There is a Static Class in the System.Windows.Forms Namespace that contains other applicaiton wide methods which are available from C# and VB, but as VB developers many times we assume the Application is always the My.Application class, which is actually a tricky link up in VB back end.  (Similar is how the My.Settings is actually a Hidden Module in the Settings.Designer.vb which has a single shared property "Settings".  This points to the MySettings module with the shared property [Default] which points to the shared field member defaultInstance. 

    thus when you access My.Settings you are actually referencing:

    Global.ApplicationName.MySettingsModule.Settings
       {Returns MySettings.[Default]}

    The Same is True with My.Application, thus it is imperative when assisting VB programmers to explicitly point out the System.Windows.Form.Application class, to not be confusing to the Compiler which infers My.Application when Application is not prefixed with any namespace, and Application.<Blah> will defaultly point to My.Application where <Blah> is not a member.

    Hope this helps
    Jaeden "Sifo Dyas" al'Raec Ruiner







    "Never Trust a computer. Your brain is smarter than any micro-chip."