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事件非常象。这里是我对onstart和onstop设计的编码: 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 基于窗体的用户界面生成应用程序。 class library 为其他应用程序中生成class libraries。 windows control library 在基于windows的控件。 web application 用静态或动态web页面作为用户界面生成应用程序。 web service 从其它应用程序中生成 web services 。 web control library 生成在web 应用程序中的控件。 console application 用于生成命令行应用程序。 windows service 为windows生成服务。