2010-01-31 74 views

回答

2

我会先购买符合您学习速度的书籍(或教程)。但请记住,能够创建应用程序和能够创建“抛光”应用程序之间经常存在差距。你不会从书本中得到这些;你从创建大量的应用程序中获得了!

这里有一个像样的地方开始(而且是免费的):Visual Basic Developer Center

从上述站点:Learning Visual Basic from the Ground Up

一旦你熟悉基础知识,看看windowsclient.net

5

这是不创建一个精致的应用程序是一项简单的任务。这需要很多时间和经验。

.NET中的有效错误处理可以通过处理'未处理的'线程和域例外来实现。

以下代码是执行此操作的应用程序的示例。你会想派生你自己的Form实例。

买这本书的好书也是学习如何做到这一点的有效方法。


Module modMain 

    Public Sub Log(ByVal ex As Exception) 

     Try 

      Dim logDirectory As String = IO.Path.Combine(Application.StartupPath, "Log") 
      Dim logName As String = DateTime.Now.ToString("yyyyMMdd") & ".txt" 
      Dim fullName As String = IO.Path.Combine(logDirectory, logName) 

      If Not IO.Directory.Exists(logDirectory) Then 
       IO.Directory.CreateDirectory(logDirectory) 
      End If 

      Dim errorString As String = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss") & " >> " & _ 
             ex.Message & Environment.NewLine & _ 
             ex.StackTrace & Environment.NewLine 

      IO.File.AppendAllText(fullName, errorString) 

     Catch ignore As Exception 

     End Try 

    End Sub 

    Public Sub ThreadExceptionHandler(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs) 
     Log(e.Exception) 
    End Sub 

    Public Sub DomainExceptionHandler(ByVal sender As Object, ByVal e As System.UnhandledExceptionEventArgs) 
     Dim ex As Exception = CType(e.ExceptionObject, Exception) 
     Log(ex) 
    End Sub 

    Public Sub Main() 

     AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler 
     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException) 

     AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf DomainExceptionHandler 

     Try 
      Application.Run(New Form) 
     Catch ex As Exception 
      Log(ex) 
     Finally 
      RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler 
      RemoveHandler AppDomain.CurrentDomain.UnhandledException, AddressOf DomainExceptionHandler 
     End Try 

    End Sub 

End Module 
+0

+1这里的MSDN文档中的示例代码的链接http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx – MarkJ 2010-01-31 21:14:05

相关问题