imports system imports microsoft.visualbasic module module1 sub main() dim i, count as integer try count = cint(command()) for i = 1 to count console.writeline("hello") next catch console.writeline("invalid argument") end try end sub end module
這些代碼和vb6窗體中的load/unload/activate/deactivate事件非常象。這里是我對(duì)onstart和onstop設(shè)計(jì)的編碼: protected overrides sub onstart(byval args() _ as string) dim fs as new filestream ( "c:/log.txt", _ filemode.openorcreate, fileaccess.write) dim sw as new streamwriter(fs) sw.basestream.seek(0, seekorigin.end) sw.writeline("service started: " + cstr(now())) sw.close() end sub
protected overrides sub onstop() dim fs as new filestream("c:/log.txt", _ filemode.openorcreate, fileaccess.write) dim sw as new streamwriter(fs) sw.basestream.seek(0, seekorigin.end) sw.writeline("service stopped: " + cstr(now())) sw.close() end sub
public sub timer1_tick(byval sender as object, _ byval e as system.eventargs) handles timer1.tick dim logrecord as string = cstr(now())+ " " dim fs as new filestream("c:/log.txt", _ filemode.openorcreate, fileaccess.write) dim sw as new streamwriter(fs) logrecord += performancecounter1.nextvalue.tostring sw.basestream.seek(0, seekorigin.end) sw.writeline(logrecord) sw.close() end sub
windows application 通過windows 基于窗體的用戶界面生成應(yīng)用程序。 class library 為其他應(yīng)用程序中生成class libraries。 windows control library 在基于windows的控件。 web application 用靜態(tài)或動(dòng)態(tài)web頁面作為用戶界面生成應(yīng)用程序。 web service 從其它應(yīng)用程序中生成 web services 。 web control library 生成在web 應(yīng)用程序中的控件。 console application 用于生成命令行應(yīng)用程序。 windows service 為windows生成服務(wù)。