2010-01-31 35 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

相關問題