其中的主要功能是在VB.Net是在、主要功能、Net、VB

2023-09-04 02:50:30 作者:待我成佛,灭了哈佛

我已经采取了支持VB.Net WinForms应用程序中。我其实是一个C#开发人员,我更熟悉的Visual Studio项目C#项目的设置。现在,我想确定为什么我的应用程序崩溃在一个特定的XP安装,我读到这里的建议

http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/53c2de93-ab33-41d0-b5dd-7ca5fbfa5c24/

要在主函数中添加一个try catch块。此建议在大约从底部第五交。 (我将在下文中引用它),但是,如果我看在VB.Net Visual Studio项目中,我没有找到一个main()方法。我所发现的是一个Application.myapp文件中叫我的项目灰色文件夹。这个文件有一个相关的设计文件,但如果我点击它,我看到下面的XML:

 < XML版本=1.0编码=UTF-8&GT?;
< MyApplicationData的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema>
  < MySubMain>真< / MySubMain>
  <的MainForm> MDIMain< /的MainForm>
  < SingleInstance>假< / SingleInstance>
  &其中; ShutdownMode> 0℃/ ShutdownMode>
  < EnableVisualStyles>真< / EnableVisualStyles>
  &其中; AuthenticationMode> 0℃/ AuthenticationMode>
  < SaveMySettingsOnExit>真< / SaveMySettingsOnExit>
< / MyApplicationData>
 

因此​​,谁能赐教到实际的主要过程调用这个VB.Net项目,所以我可以尝试赶上正在发生的异常。如果像我怀疑,但实际上不是一个主要的程序在我的VB.Net项目,有人可以也许让我知道我怎么能去这样做在我的项目如下:

  [STAThread]
静态无效的主要()
{
    尝试
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(假);
        Application.Run(新Form1中());
    }
    赶上(System.IO.FileNotFoundException前)
    {
        的MessageBox.show(ex.Message +\ñ\ñ\ N+ ex.StackTrace);
    }
}
 
VB.net 我想实现几个效果

解决方案

更​​VB的方式做,这是打开应用程序的属性,然后单击ViewApplicationEvents按钮。这将打开Application.xaml.vb文件,您可以为应用程序添加自定义事件处理程序。从左侧的下拉应用程序事件,你可以轻松地访问了一堆的事件,包括DispatcherUnhandledException,激活,导航,启动,退出,等你还可以在这里通过从左侧下拉菜单并选择选择Applciation添加Main方法主要从右侧下拉。

在的WindowsForms应用的情况下,这个过程是相似的。然而,当您选择Applciation活动按钮,所显示的文件是ApplicationEvents.vb的文件。在这里,要添加一个全球性的错误处理程序,选择左侧的下拉菜单,选择MyApplication的事件。然后在右边的下拉列表中,添加UnhandledException处理程序。您还可以在这里创建你的主要方法为好。

I have taken over support of a VB.Net WinForms application. I am actually a c# developer and am more familiar with the setup of visual studio projects in c# projects. Now I am trying to determine why my application is crashing on a specific XP installation, and I read the suggestion here

http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/53c2de93-ab33-41d0-b5dd-7ca5fbfa5c24/

to add a try catch block in the main function. This is suggested in about the 5th post from the bottom. (I will quote it below) However, if I look in the VB.Net visual studio project, I do not find a Main() procedure. What I do find is a grey folder called "My project" with a "Application.myapp" file inside it. This file has an associated designer file, but if I click on it I see the following xml:

<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MySubMain>true</MySubMain>
  <MainForm>MDIMain</MainForm>
  <SingleInstance>false</SingleInstance>
  <ShutdownMode>0</ShutdownMode>
  <EnableVisualStyles>true</EnableVisualStyles>
  <AuthenticationMode>0</AuthenticationMode>
  <SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

So can anyone enlighten me to where the actual main procedure call is for this VB.Net project so that I can try catch the exception that is occurring. If, as I suspect, there isn't actually a Main procedure in my VB.Net project, can someone maybe let me know how I can go about doing the following in my project:

[STAThread]
static void Main()
{
    try
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
    catch (System.IO.FileNotFoundException ex)
    {
        MessageBox.Show(ex.Message + "    \n\n\n" + ex.StackTrace);
    }
}

解决方案

The more VB way to do this is to open the Application properties and click on the ViewApplicationEvents button. This will open the Application.xaml.vb file where you can add custom event handlers for the application. Select Application Events from the left drop-down and you can easily access a bunch of events including DispatcherUnhandledException, Activated, Navigating, Startup, Exit, etc. You can also add the Main method here by selecting Applciation from the left drop-down and selecting Main from the right drop down.

In the case of WindowsForms applications, the process is similar. However when you select the Applciation Events button, the file that is shown is the ApplicationEvents.vb file. In here, to add a global error handler, select the left drop-down and select MyApplication Events. Then in the right drop-down, add the UnhandledException handler. You can also create your Main method here as well.